Jump to content

Action depending on drop down


gnawz

Recommended Posts

Hi

 

I have a drop down thus

 

 

<form name = frmUtils method = POSTaction = "">

<select name = Do>

<option>Add</option>

<option>Delete</option>

<option>Update</option>

</select>

</form>

 

I want the form action to change based on the selection ie

 

if selected Index is Add

action = add.php

 

 

if selected Index is Delete

action = delete.php

 

 

if selected Updateis Add

action = update.php

 

Somebody help

 

 

Link to comment
https://forums.phpfreaks.com/topic/61339-action-depending-on-drop-down/
Share on other sites

Note: The code is not tested be aware of that...

 

 

<script type="text/javascript">
function do_action_page(form) {
var select_form = "";
var select_form = form.select_action.value;
if(select_form == ''){
	alert('empty select');
}
else {
	var select_form = form.frmUtils.action;
}
}
</script>
<select name="select_action" onchange="return do_action_page(this)">
<option value="add.php">add.php</option>
<option value="delete.php">delete.php</option>
<option value="update.php">update.php</option>
</select>

#this must be php file
$content = "";
$content .= "<form name = 'frmUtils' method = 'POST' action="">";
$content .= "<select name = Do>";
$content .= "<option>Add</option>";
$content .= "<option>Delete</option>";
$content .= "<option>Update</option>";
$content .= "</select>";
$content .= "</form>";
echo $content;

Thanks for your help.  I'm trying it out but still troublesome

I want to put my actions in a switch

 

like

 

$Action = $_GET ['Function']

 

switch($Action)

{

 

case 'add':

      add function;

break;

 

case 'update':

    update function;

break;

 

case 'delete':

    delete function;

break;

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.