Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    passing data from column to nother column

    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.
    Code:
    <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
    Code:
    <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 ??

    full relevent code.

    Code:
    <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>&nbsp;</TD>
          <TD><input type="submit"  id="submit2" value="Update" /></TD>
          <TD>&nbsp;</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>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,219
    Thanks
    23
    Thanked 606 Times in 605 Posts
    It is not <option selected="selected"></option>
    it's
    <option selected></option>

  • #3
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Using 'selected="selected"' is XHTML and not just completely fine, it's even better in terms of future stability.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,219
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Guess the absence of a doctype left things wide open.
    I was using <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


    @hyster give this page a read for your answer http://www.mredkj.com/tutorials/tutorial007.html

  • Users who have thanked sunfighter for this post:

    hyster (01-19-2013)

  • #5
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Yeah, the Doctype has to be set correctly, of course.

  • #6
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thx guys i got that part sorted now for the next problem lol.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •