how to use javascript variable value in jsp?

javascript problem!!

  • I'm having a problem with a form that passes values from one select box to the next. It works fine, except that the name of the receiving box contains a period (so to work with mySQL) tablename.fieldname. Javascript doesn't like this. How can I fix it? thanks So, this works: <form name="combo_box"> <table><tr><td> <select multiple size="10" name="list1" style="width:150"> <option>red</option> <option>white</option> <option>blue</option> </select> </td> <td align="center" valign="middle"> <input type="button" onClick="move(this.form.frack,this.form.list1)" value="<<"> <input type="button" onClick="move(this.form.list1,this.form.frack)" value=">>"> </td> <td> <select multiple size="10" name="frack" style="width:150"> </select> </td></tr></table> </form> But if instead of "Frack" the second select box has to be named "tablename.fieldname" how do I get it to work? Please help!!! I read somewhere that I could use this.form.elements['hey.you'] but that doesn't work either <form name="combo_box"> <table><tr><td> <select multiple size="10" name="list1" style="width:150"> <option>red</option> <option>white</option> <option>blue</option> </select> </td> <td align="center" valign="middle"> <input type="button" onClick="move(this.form.list1,this.form.elements['hey.you'])" value="<<"> <input type="button" onClick="move(this.form.elements['hey.you'],this.form.list1)" value=">>"> umh </td> <td> <select multiple size="10" name="hey.you" style="width:150"> </select> </td></tr></table> </form> Thanks in advance Will The following is the scrip in the header although I don't think that it matters, the problem is that element name with a period! <script LANGUAGE="JavaScript"> <!-- Original: Phil Webb ([email protected]) --> <!-- Web Site: http://www.philwebb.com --> <!-- Begin function move(fbox, tbox) { var arrFbox = new Array(); var arrTbox = new Array(); var arrLookup = new Array(); var i; for (i = 0; i < tbox.options.length; i++) { arrLookup[tbox.options[i].text] = tbox.options[i].value; arrTbox[i] = tbox.options[i].text; } var fLength = 0; var tLength = arrTbox.length; for(i = 0; i < fbox.options.length; i++) { arrLookup[fbox.options[i].text] = fbox.options[i].value; if (fbox.options[i].selected && fbox.options[i].value != "") { arrTbox[tLength] = fbox.options[i].text; tLength++; } else { arrFbox[fLength] = fbox.options[i].text; fLength++; } } arrFbox.sort(); arrTbox.sort(); fbox.length = 0; tbox.length = 0; var c; for(c = 0; c < arrFbox.length; c++) { var no = new Option(); no.value = arrLookup[arrFbox[c]]; no.text = arrFbox[c]; fbox[c] = no; } for(c = 0; c < arrTbox.length; c++) { var no = new Option(); no.value = arrLookup[arrTbox[c]]; no.text = arrTbox[c]; tbox[c] = no; } } // End --> </script>

  • Answer:

    Dear rayhomme, Referring to the hey.you element as this.form.elements['hey.you'] is supposed to work according to the JavaScript specifications, but some browser implementations, especially older ones, may not parse the code correctly. A method guaranteed to work in any reasonable browser is to refer to form elements by number. Elements are numbered starting from 0. Each select, input, and textarea counts as an element. In your case, the form contains, in order: a select element (number 0); an input element (number 1); another input element (number 2); and a final select element (number 3). Thus, list1 is element 0 of the form, while hey.you is element 3. This means that you can replace the lines <input type="button" onClick="move(this.form.elements['hey.you'],this.form.list1)" value="<<"> <input type="button" onClick="move(this.form.list1,this.form.elements['hey.you'])" value=">>"> with <input type="button" onClick="move(this.form.elements[3],this.form.list1)" value="<<"> <input type="button" onClick="move(this.form.list1,this.form.elements[3])" value=">>"> or even with the following. <input type="button" onClick="move(this.form.elements[3],this.form.elements[0])" value="<<"> <input type="button" onClick="move(this.form.elements[0],this.form.elements[3])" value=">>"> This style of reference will work regardless of what you name the elements. It has been a pleasure to address this question on your behalf. If you have trouble implementing or testing this code change, please ask for a Clarification Request before you rate my answer. Regards, leapinglizard

rayhomme-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.