简体   繁体   中英

how to have each option in a drop down list call a different function when submit is selected?

I have a simple form with 5 option values (test, test1, test2, test3, test4). When the user selects the submit button for either one, I need for it to call a different function (function test1(), function test2(), etc....)

using some php I need for these functions to be called on submit.

I am trying something like if (isset(_POST['test1']) && (isset(_POST['submit'] { test1(); } else if ...

I cant seem to get this to call the function. Maybe I have the value wrong for each option. I just have the values - value="test" value="test1" and so on.

Any suggestions are greatly appreciated..Thanks

You need to put a name to the selector:

<select name="selector">
    <option value="test">Test</option>
    <option value="test1">Test1</option>
</select>

Then check the value of the selector

<?php
if (isset($_POST['selector']) && 'test' == $_POST['selector']) { 
    test(); 
} 
else if (isset($_POST['selector']) && 'test1' == $_POST['selector']) { 
    test1(); 
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM