I have 2 action forms in the page and 2 submit buttons.
1 is zoom-level
1 is refresh rate in seconds
When I hit submit of zoom, the refresh rate is reset When I hit submit of refresh rate, the zoom level is reset
What to do to keep the value of the other when one dropdown is set to a certain value?
I think this is a common problem where noobs struggle with, so it would be nice to have some good explanation from experts with nice guidance here...
code is:
<?php
$submittedValue = "";
$value0 = 1;
$value1 = 1.2;
$value2 = 1.5;
$value3 = 2;
if (isset($_POST["FruitList"])) {
$submittedValue = $_POST["FruitList"];
}
?>
<form action="example3b2vandaag.php" name="fruits" method="post">
<select project="FruitList" id="FruitList" name="FruitList">
<option value = "<?php echo $value0; ?>"<?php echo ($value0 == $submittedValue)?" SELECTED":""?>><?php echo "off"; ?></option>
<option value = "<?php echo $value1; ?>"<?php echo ($value1 == $submittedValue)?" SELECTED":""?>><?php echo $value1; ?></option>
<option value = "<?php echo $value2; ?>"<?php echo ($value2 == $submittedValue)?" SELECTED":""?>><?php echo $value2; ?></option>
<option value = "<?php echo $value3; ?>"<?php echo ($value3 == $submittedValue)?" SELECTED":""?>><?php echo $value3; ?></option>
</select>
<input type="submit" name="submit" id="submit" value="Set zoom level" />
</form>
<?php
$submittedValue = "";
$value0 = 1000;
$value1 = 20000;
$value2 = 30000;
$value3 = 90000;
if (isset($_POST["FruitList2"])) {
$submittedValue = $_POST["FruitList2"];
}
?>
<form action="example3b2vandaag.php" name="fruits2" method="post">
<select project="FruitList2" id="FruitList2" name="FruitList2">
<option value = "<?php echo $value0; ?>"<?php echo ($value0 == $submittedValue)?" SELECTED":""?>><?php echo $value0; ?></option>
<option value = "<?php echo $value1; ?>"<?php echo ($value1 == $submittedValue)?" SELECTED":""?>><?php echo $value1; ?></option>
<option value = "<?php echo $value2; ?>"<?php echo ($value2 == $submittedValue)?" SELECTED":""?>><?php echo $value2; ?></option>
<option value = "<?php echo $value3; ?>"<?php echo ($value3 == $submittedValue)?" SELECTED":""?>><?php echo $value3; ?></option>
</select>
<input type="submit" name="submit" id="submit" value="Set refresh milliseconds" />
</form>
I don't see any reason why you would want two forms, you can put the two select boxes into one form. And please don't use unintelligent variable names such as $value0, $submittedValue and $Fruitlist, because this isn't about fruits.
Here are the two select boxes into one form:
To use the data you get from the form you can use $_POST["zoom"] and $_POST["refresh"], because that's what the name properties of the select boxes are. See http://www.w3schools.com/php/php_form_complete.asp for more information on html forms and how to use the $_POST data.