Hi, I've got some code here, it it just php and html so you'll be able to see it working.

As you can see, I have 6 drop down list boxes. Each box contains numbers, whatever the user clicks I assign to a variable (there's one variable per box).

But, the stupid boxes don't stay on what number they're supposed to , ie clicked to, they go back to zero (well maybe I'm stupid. Well I don't care)

Also, when I set a number in one box, and click a different box, the original box gets reset to zero.

Here's the code.

<html>
<head>
</head>
<body>
<?php
if (!isset($_POST[Mode1])) {
  $Mode1 = 1;
}else{
  $Mode1 = $_POST[Mode1];
}
if (!isset($_POST[Mode2])) {
  $Mode2 = 1;
}else{
  $Mode2 = $_POST[Mode2];
}
if (!isset($_POST[Mode3])) {
  $Mode3 = 1;
}else{
  $Mode3 = $_POST[Mode3];
}
if (!isset($_POST[Mode4])) {
  $Mode4 = 1;
}else{
  $Mode4 = $_POST[Mode4];
}
if (!isset($_POST[Mode5])) {
  $Mode5 = 1;
}else{
  $Mode5 = $_POST[Mode5];
}
if (!isset($_POST[Mode6])) {
  $Mode6 = 1;
}else{
  $Mode6 = $_POST[Mode6];
}
print "<table>";
print "<tr><td>";
print "<H3>Item 1</H3>";
print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
print "<SELECT NAME='Mode1' onChange='submit()'>";
print "<OPTION VALUE='0'>0";
print "<OPTION VALUE='1'>1";
print "<OPTION VALUE='2'>2";
print "<OPTION VALUE='3'>3";
print "<OPTION VALUE='4'>4";
print "</form>";
print "</td>";
print "<td>";
print "<H3>Item 2</H3>";
print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
print "<SELECT NAME='Mode2' onChange='submit()'>";
print "<OPTION VALUE='0'>0";
print "<OPTION VALUE='1'>1";
print "<OPTION VALUE='2'>2";
print "<OPTION VALUE='3'>3";
print "<OPTION VALUE='4'>4";
print "</form>";
print "</td></tr>";
print "<tr><td>";
print "<H3>Item 3</H3>";
print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
print "<SELECT NAME='Mode3' onChange='submit()'>";
print "<OPTION VALUE='0'>0";
print "<OPTION VALUE='1'>1";
print "<OPTION VALUE='2'>2";
print "<OPTION VALUE='3'>3";
print "<OPTION VALUE='4'>4";
print "</form>";
print "</td>";
print "<td>";
print "<H3>Item 4</H3>";
print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
print "<SELECT NAME='Mode4' onChange='submit()'>";
print "<OPTION VALUE='0'>0";
print "<OPTION VALUE='1'>1";
print "<OPTION VALUE='2'>2";
print "<OPTION VALUE='3'>3";
print "<OPTION VALUE='4'>4";
print "</form>";
print "</td></tr>";
print "<tr><td>";
print "<H3>Item 5</H3>";
print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
print "<SELECT NAME='Mode5' onChange='submit()'>";
print "<OPTION VALUE='0'>0";
print "<OPTION VALUE='1'>1";
print "<OPTION VALUE='2'>2";
print "<OPTION VALUE='3'>3";
print "<OPTION VALUE='4'>4";
print "</form>";
print "</td>";
print "<td>";
print "<H3>Item 6</H3>";
print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
print "<SELECT NAME='Mode6' onChange='submit()'>";
print "<OPTION VALUE='0'>0";
print "<OPTION VALUE='1'>1";
print "<OPTION VALUE='2'>2";
print "<OPTION VALUE='3'>3";
print "<OPTION VALUE='4'>4";
print "</form>";
print "</td></tr>";
print $Mode1."<BR>";//Incidentally, why are these at the top of the page, not the bottom?
print $Mode2."<BR>";
print $Mode3."<BR>";
print $Mode4."<BR>";
print $Mode5."<BR>";
print $Mode6."<BR>";
?>
</A></A><body><html>

What I would dearly love, is for the boxes to stay on what they are clicked to, and for them not to reset all the other boxes back to zero.

PS - Each box has to submit() on their onChange, not click all six boxes then click some button which updates them all, zey must be independant...

Huge thanks and kudos in advance.

(Gregg)

    Do this for each Mode select... Change the applicable NAME and $_POST['ModeX'] names for each one. Put it all into one form instead of separate forms for each.

    // Only have one FORM opening tag at the beginning.
    print "<form action='$_SERVER[PHP_SELF]' method='POST'>"; 
    
    
    // Mode1 Select Box
    print "<SELECT NAME='Mode1' onChange='submit()'>";
    $range = range(0, 4);
    FOREACH($range AS $v){
    	$selected = "";
    	IF(ISSET($_POST['Mode1']) && $_POST['Mode1'] == $v) $selected = "SELECTED";
    	print "<OPTION VALUE='$v' $selected>$v</option>"; 
    }
    print "</select>"; 
    
    // Mode2 Select Box
    print "<SELECT NAME='Mode2' onChange='submit()'>";
    $range = range(0, 4);
    FOREACH($range AS $v){
    	$selected = "";
    	IF(ISSET($_POST['Mode2']) && $_POST['Mode2'] == $v) $selected = "SELECTED";
    	print "<OPTION VALUE='$v' $selected>$v</option>"; 
    }
    print "</select>"; 
    
    // Then add the others for the other Mode Selects.
    
    // Only have one FORM close tag at the end.
    print "</form>"; 
    

    The modes are being displayed at the top instead of the bottom because you didn't close out your table with the </table> tag...

      I had to edit my code, so try the way I have it now... (above)

        Defender, you rule........!

        <html>
        <head>
        </head>
        <body>
        <?php
        print "<form action='$_SERVER[PHP_SELF]' method='POST'>";
        drawDropBoxes(6);
        print "</form>";
        function drawDropBoxes($n){
          for( $i=1; $i<=$n; $i++ ){
        	$mode = "Mode".$i;
        	print "<SELECT NAME=$mode onChange='submit()'>"; 
        	$range = range(0, 4);
        	FOREACH($range AS $v){ 
        		$selected = ""; 
        		IF(ISSET($_POST[$mode]) && $_POST[$mode] == $v) $selected = "SELECTED"; 
            		print "<OPTION VALUE='$v' $selected>$v</option>";
        	}
        	print "</select>";  
        } } ?>

          Glad I could help... I knew you could make it into a function and shrink it way down, but I wanted you to see the premise behind how to make it work... The code looks great!

            Write a Reply...