0

i wanna swap dropdown value on change event as if i select the value from '4' to '1' in dropdown then it will change the value of that drop down having value '1' my code is define as under,

 <?php

 $host="****"; // Host name 
 $username="***"; // Mysql username 
     $password="****"; // Mysql password 
         $db_name="****"; // Database name 
         $tbl_name="*****"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$arr = explode("?", $_SERVER['REQUEST_URI']);
$arr1=explode("&",$arr[1]);
$arr2=explode("=",$arr1[0]);

$sql="SELECT * FROM $tbl_name where idTemplates=$arr2[1]";
$result=mysql_query($sql);
$count=0;
//$templateName=mysql_result($result,$i,"TempName");
//$tempID=mysql_result($result,$i,"idTemplates");
$Section1=mysql_fetch_row($result);
for($j=6;$j<=15;$j++)
{
if($Section1[$j]!="")
{
$count++;  
}
}
for($j=6;$j<=15;$j++)
{
if($Section1[$j]!="")
{
echo("<tr>");
      echo("<td>");
      echo("$Section1[$j] <input type='hidden' value='$Section1[$j]' name='Sections[]' />");
           echo("</td>");
echo("<td>");
$counting=$j-5;
echo("<select id='Numbering".$counting."' onchange='OnChangeSelection(Numbering".$counting.".options[Numbering".$counting.".selectedIndex].value);'>");
for($k=1;$k<=$count;$k++)
{
if($k==($j-5))
{
echo("<option value='$k' selected='".$counting."'>$k</option>");
}
else
{
echo("<option value='$k'>$k</option>");
}
}
echo("</select>");
echo("</td>");
           echo("</tr>");
}
}
?>

in the above code i am printing three column first section is section name and second column is section details and third is combo dropdown box having nuber value in it as shown in the fig,

enter image description here

and this is the js on change,

function OnChangeSelection(selection)
{
alert(selection);
}

how to alter it so that as we change the drop down value it would change the other drop down having same value ??

hopes for your suggestions thanks in advance

Syed Raza
  • 331
  • 2
  • 13
  • 35
  • Drop-downs are the ones with 8, 9 and 10 selected in the image. Do you want when one is changed the other ones to have the same value? – Angel Jul 18 '12 at 07:28
  • Please pick and apply an [indent style](http://en.wikipedia.com/wiki/Indent_style) to make your code readable. Once working, you should make use of [codereview.SE](http://codereview.stackexchange.com/) to get feedback on the many issues with the script (e.g. SQL injection, outdated mysql extension, [`or die`](http://www.phpfreaks.com/blog/or-die-must-die)). – outis Jul 18 '12 at 07:36
  • duplicate of [How do I programatically set the value of a select box element using javascript?](http://stackoverflow.com/q/78932/), [Change text based on select box value](http://stackoverflow.com/q/4471679/), or one of *many*, ***MANY*** others. – outis Jul 18 '12 at 07:38
  • @angel yes i f i change from 8 to 9 then the drop down having value 9 would chang to 8 – Syed Raza Jul 18 '12 at 07:52

2 Answers2

0

You call call one Ajax function while choosing the first combo to load the second drop down.

user1259132
  • 320
  • 2
  • 3
  • 11
0

I've done a little sample of what you need here: http://jsfiddle.net/u8ySM/

Hope it helps!

Angel
  • 1,180
  • 9
  • 13