How to pass an array created in javascript to another jsp and then use that array in a java function on that jsp? -
here script have , want able pass array "playernames" java function on .jsp. i'm wonder how pass array page , retrieve java function.
<script> function getplayernames() { var selected = document.queryselectorall("#selected-players > tr > td"); var playernames = []; for(var i=0; i<selected.length; ++i){ var id = selected[i].getattribute('id'); if (id.indexof('player')>-1) { playernames.push(selected[i].textcontent); } } } </script>
edit:
<td style="vertical-align: top;"><button onclick="getplayernames()"id="generate">generate</button><br></td> <input type="hidden" id="players" /> <script> function getplayernames(){ var selected = document.queryselectorall("#selected-players > tr > td"); var playernames = []; for(var i=0; i<selected.length; ++i){ var id = selected[i].getattribute('id'); if (id.indexof('player')>-1) { playernames.push(selected[i].textcontent); } } document.getelementbyid("players").values=playernames; document.getelementbyid("players").submit(); window.location.replace("lineups.jsp"); }</script>
other jsp
<%string[] players = request.getparametervalues("players");%>
you'll need have hidden field inside form tags id , action attributes set below.
<td style="vertical-align: top;"><button onclick="getplayernames()"id="generate">generate</button><br></td> <form id="playernames" action="url"> // in action give url of jsp page want send values lineups.jsp in case guess. <input type="hidden" id="players" name="players" /> </form> <script> function getplayernames(){ var selected = document.queryselectorall("#selected-players > tr > td"); var playernames = []; for(var i=0; i<selected.length; ++i){ var id = selected[i].getattribute('id'); if (id.indexof('player')>-1) { playernames.push(selected[i].textcontent); } } document.getelementbyid("players").value=playernames; document.getelementbyid("playernames").submit(); }</script>
Comments
Post a Comment