user55555
user55555

Reputation: 43

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

Upvotes: 0

Views: 795

Answers (1)

artberri
artberri

Reputation: 1357

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(); 
} 

Upvotes: 0

Related Questions