0

I have a page with 2 select option dropdown lists and I can only use one of them each time I have to submit the selected option but if I use two and click on submit i get an error Only use one list and thats how it should work.

for example:

I have 2 drop lists like this one enter image description here enter image description here enter image description here

enter image description here

enter image description here enter image description here

if i choose both like the pic above and click on submit I get an error and the selected options are shown as the deffult option and thats what I want, but when I click on the reset button it need to reset them to the default value but nothing happens.

like this

enter image description here

The Options for the dropdown list is from two different arrays.

$test1 and $test2 are two different arrays

<form name="rechner" method = "POST">
<select name="one">
    <option value="" selected hidden>Choose One</option>
           <?php foreach ($test1 as $one => $value) { ?>
           <option value="<?= $value ?>" 
           <?php if ($_POST['one'] == $value) { 
                     echo 'selected="selected"';}?> ><?= $value ?>
            </option><?php
                }
            ?>
</select> 

<select name="two">
    <option value="" selected hidden>Choose one</option>
        <?php foreach ($test2 as $two => $value) { ?>
        <option value="<?= $value ?>" 
        <?php if ($_POST['two'] == $value) {
                  echo 'selected="selected"';}?> ><?= $value ?>
         </option><?php
        }
        ?>
</select> 
<input type="submit" name="calc" value="Submit" />
<input type="reset" name="reset" value="Reset">

</form>

  if ($_POST['calc'] == "Berechnen") {
    /// do something
 }


M.Aldein
  • 41
  • 7
  • 2
    Provide complete sample of your codes to get helps. – Chaska May 03 '19 at 10:42
  • Or please provide a [mcve]. – Til May 05 '19 at 12:55
  • What do you expect that button to do? Any reset button should only reset the form's fields to the state in which they were loaded, and if you write some configuration to the initial markup (like you do in that `foreach` loop), you modify the state – Nico Haase May 06 '19 at 07:22

1 Answers1

0

found the answer on other question Here

<script type="text/javascript">
      function resetForm($myform) {
            $myform.find('input:password, input:file, select, textarea').val('');
            $myform.find('input:radio,input:checkbox')
                        .removeAttr('checked').removeAttr('selected);
     }
</script>
<form name="rechner" method = "POST" id="myform">
           /////html code/////

<input type="button" value="Reset" onclick="resetForm($('#myform'));">
</form>
M.Aldein
  • 41
  • 7