简体   繁体   中英

how can i send in jsp page with javascript or jquery to spring controller (with use <a href=> tag)?

I'd like to know about javascript to send spring controller with use <a> tag.

<jsp page>

<a link="#" onClick="jsFunctionName()">Post_a_link</a>
<form name="form_Name" method="post">
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
  <input type="checkbox" name="check_Box" value="(somethings else values..)"/>
  <input type="checkbox" name="check_Box" value="(somethings else values..)"/>
</form>

 function jsFunctionName(){
  document.form_Name.action="/spring_Controller.do";
  document.getElementsByName("check_Box").checked.submit();

then "Chrome," said to me " Cannot read property 'submit' of undefined"

help me to fix this error.........thanks...

You can try this Solution

function signUp() {

    document.forms[0].action= "<%=request.getContextPath()%>/spring_Controller.do";
    document.forms[0].method="post";
    document.forms[0].submit();
}

<form name="form_Name" method="post">
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
</form>

<a href="javascript: submitform()">Post_a_link</a>

or try this also if multiple forms

function signUp() {
    var form = document.getElementById('form_name');
    form.action= "<%=request.getContextPath()%>/spring_Controller.do";
    form.method="post";
    form.submit();
}

<form id="form_name" name="form_Name" method="post">
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
<input type="checkbox" name="check_Box" value="(somethings else values..)"/>
</form>

<a href="javascript: submitform()">Post_a_link</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM