Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2013, 09:17 AM   PM User | #1
hyster
New to the CF scene

 
Join Date: Jan 2013
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
hyster is an unknown quantity at this point
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>
hyster is offline   Reply With Quote
Old 01-19-2013, 02:03 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
It is not <option selected="selected"></option>
it's
<option selected></option>
sunfighter is offline   Reply With Quote
Old 01-19-2013, 02:07 PM   PM User | #3
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 348
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
Using 'selected="selected"' is XHTML and not just completely fine, it's even better in terms of future stability.
Airblader is offline   Reply With Quote
Old 01-19-2013, 02:23 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
hyster (01-19-2013)
Old 01-19-2013, 02:30 PM   PM User | #5
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 348
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
Yeah, the Doctype has to be set correctly, of course.
Airblader is offline   Reply With Quote
Old 01-19-2013, 04:49 PM   PM User | #6
hyster
New to the CF scene

 
Join Date: Jan 2013
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
hyster is an unknown quantity at this point
thx guys i got that part sorted now for the next problem lol.
hyster is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 AM.


Advertisement
Log in to turn off these ads.