neverlucky neverlucky - 4 years ago 92
PHP Question

form using action from dropdownlist

I have 5 Forms like this

<p>
Form1:
<form action='Form1.php' method='POST'>
<input name='charname' id='charname' placeholder='Charname'>
<input name='server' id='server' placeholder='Server'>
<input name='region' id='region' placeholder='Region'>
<input type='submit' name='submit'>
</form>
</p>


Now I want to replace the 5 forms with a single form, where the
action
is taken from a dropdown-list like this:

<select name="dropdown" size="5">
<option value="form1.php">Form1</option>
<option value="form2.php">Form2</option>
<option value="form3.php">Form3</option>
<option value="form4.php">Form4</option>
<option value="form5.php">Form5</option>
</select>


How can I achieve this?

Thanks in advance

Answer Source

You should use jQuery for this

Example-

HTML

<select name="dropdown" id="formaction" size="5">
   <option value="form1.php">Form1</option>
   <option value="form2.php">Form2</option>
   <option value="form3.php">Form3</option>
   <option value="form4.php">Form4</option>
   <option value="form5.php">Form5</option>
</select> 

jQuery Code

<script>
$("#formaction").on("change", function() {
  var getVal = $(this).val();
        $("#YourFormId").attr("action", getVal); //replace #YourFormId with your form id
});
</script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download