java - How to give jsp path to a function in javascript -


i have jsp page

"addsource.jsp"

present in eclipse shown in picture. enter image description here

now question have javascript function have give "addsource.jsp" in can move page current jsp page on button click.the code follows

 function addrow(type) {            if (type == '') {                 alert("field empty");             }          else {          var table = document.getelementbyid('my_table'); //html table          var rowcount = table.rows.length; //no. of rows in table          var columncount =  table.rows[0].cells.length; //no. of columns in table                    var row = table.insertrow(rowcount); //insert row                         var cell1 = row.insertcell(0); //create new cell                     var element1 = document.createelement("input"); //create new element                     element1.type = "text"; //set element type           element1.setattribute('id', 'source'); //set id attribute           element1.setattribute('name','source'+rowcount);          element1.setattribute('value',type);          cell1.appendchild(element1);           }            }      function generate1() {              var table = document.getelementbyid('my_table');               var rowcount = table.rows.length;              alert(rowcount);              var f = document.form;              f.target="";              f.method="post";              f.action= 'addsource.jsp?rowcount='+rowcount;             }         <form id="form">                         <input type="text" id="origin" name="element"/>                           <table id="my_table">                                 <thead><tr>                                          <th>source</th>                                   </tr>                                 </thead>                                 <tbody>                                 </tbody>                             </table>                              <input type="button" value="add row"  name="add" onclick="addrow(document.forms[0].element.value)"  />                         <input type="submit" value=" save" /> 

you can use location.href add id form (for example formid) , use this:

<script type="text/javascript">     document.getelementbyid("formid").onclick = function () {     location.href = "addsource.jsp"; }; 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -