Author Topic: Action depending on drop down  (Read 1389 times)

0 Members and 1 Guest are viewing this topic.

Offline gnawzTopic starter

  • Enthusiast
  • Posts: 236
    • View Profile
Action depending on drop down
« on: July 23, 2007, 04:09:00 AM »
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


Offline DeadEvil

  • Enthusiast
  • Posts: 116
  • Gender: Male
  • Such A Rush !!!
    • View Profile
Re: Action depending on drop down
« Reply #1 on: July 23, 2007, 04:42:28 AM »
Note: The code is not tested be aware of that...


Code: [Select]
<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;

PHP Metal!!! Bangis!!!

@DeadEvil, please read the question first!!

Offline gnawzTopic starter

  • Enthusiast
  • Posts: 236
    • View Profile
Re: Action depending on drop down
« Reply #2 on: July 23, 2007, 08:09:21 AM »
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;
}