hyster Posted January 18, 2013 Share Posted January 18, 2013 (edited) this is a script i did using php,html and js. the php works to select the data into the 1st column and theres a button to move selected data from col1 to col 2 where i want to submit it to a database. the problem im having (as far as im aware anyway) is this line. <option selected="selected"></option> the data that is moved from col1 to col2 will not pass to the insert page (tested using get). but if i use <option selected="selected"></option> <option>test data</option> the "test data" is passed to the next page. the question is how do i get the data that is passed to col2 using JS to be passed to the insert script ?? <p> </p> <div align="center"> <form id="form2" name="form2" method="get" action="new.php"> <TABLE align="center"> <tr> <td>col 1</td> <td></td> <td>col 2</td></tr> <TR> <TD> <select size="5" name="lstBox" id="lstBox"> <option value="II - ICruiser Mk. I">ICruiser Mk. I</option> <option value="II - ICruiser Mk. ">ICruiser Mk. </option> <option value="II - ICruiser Mk. ">ICruiser Mk. </option> <option value="II - Cruiser Mk. I "> Cruiser Mk. I </option> <option value="IV - IV- Covenanter ">IV- Covenanter </option> <option value="IV - IV- Valentine ">IV- Valentine </option> <option value="V - Crusader ">Crusader </option> </select> </TD> <TD> <input name="add" type="button" value="Add" onclick="FirstListBox();" /> <input name="remove" type="button" value="Remove" onclick="SecondListBox();"/> </TD> <TD> <select name="ListBox1" size="5" multiple="multiple" id="ListBox1"> <option selected="selected"></option> </select> </TD> <TR> <TD> </TD> <TD><input type="submit" id="submit2" value="Update" /></TD> <TD> </TD></tr> </TABLE> </form> <SCRIPT type="text/javascript"> <!-- function SecListBox(ListBox,text,value) { try { var option=document.createElement("OPTION"); option.value=value; option.text=text; ListBox.options.add(option) } catch(er) { alert(er) } } function OutPut(){ for (var s=document.getElementById("ListBox1"),txt='',z0=0;z0<s.length;z0++){ txt+=s.options[z0].value+':'; } document.getElementById('ip').value=txt; } function FirstListBox(){ var count=document.getElementById("lstBox").options.length; for(var i=0;i<count;i++){ if(document.getElementById("lstBox").options[i].selected){ SecListBox(document.getElementById("ListBox1"),document.getElementById("lstBox").options[i].value,document.getElementById("lstBox").options[i].value);document.getElementById("lstBox").remove(i); break } } OutPut(); } function SortAllItems(){ var arr=new Array(); for(i=0;i<document.getElementById("lstBox").options.length;i++) { arr[i]=document.getElementById("lstBox").options[i].value}arr.sort(); RemoveAll(); for(var i=0;i<arr.length;i++){ SecListBox(document.getElementById("lstBox"),arr[i],arr[i])}}function RemoveAll(){try{document.getElementById("lstBox").options.length=0 } catch(er){ alert(er) } } function SecondListBox(){ var count=document.getElementById("ListBox1").options.length; for(var i=0;i<count;i++){ if(document.getElementById("ListBox1").options[i].selected){SecListBox(document.getElementById("lstBox"),document.getElementById("ListBox1").options[i].value,document.getElementById("ListBox1").options[i].value);document.getElementById("ListBox1").remove(i); break } } SortAllItems() OutPut(); } //--> </SCRIPT> </body> </html> Edited January 18, 2013 by hyster Quote Link to comment https://forums.phpfreaks.com/topic/273298-java-in-a-form/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.