Log in

View Full Version : Resolved How to pass several values from radio buttons



bluewalrus
05-11-2009, 04:09 AM
Is there a way to set a sub group within a radio's settings? This is the html code I have...


<input type="radio" value="$dirArray[$index]" name="modify" />
<input type="radio" value="$dirArray[$index]" name="deleteme" />

I only want the options to be "modify" or "deleteme". I don't want them to be able to select both. I can't use the same name because I want to know which function they want to perform. Thanks.

forum_amnesiac
05-11-2009, 07:34 AM
If you use the same "name" but set a different "id" for each you can use javascript to get the id and based on that decide what course of action to take. This also limites then input to a single choice.

<input type="radio" value="$dirArray[$index]" name="test" id="modify" />modify
<input type="radio" value="$dirArray[$index]" name="test" id="deleteme" />delete

After that in javascript you can get the id by testing the DOM id property.

Hope this is what you were looking for

bluewalrus
05-11-2009, 09:55 PM
I'm using it in php and the php grabs the name value so I need that to be differentiated because if they hit modify and it reads delete that would be bad and vise verse although not as bad if they hit delete and it brought them to edit.

Nile
05-11-2009, 09:59 PM
Here:


<input type="radio" value="$dirArray[$index] : modify" name="action" />
<input type="radio" value="$dirArray[$index] : deleteme" name="action" />


Just seperate the value by a : to find out what they did/want.

bluewalrus
05-12-2009, 02:53 AM
Oh, you've got it again. Thanks.

This should probably be moved to the php forum. Here's the whole solution I used.


<?php
$go = $_POST['action'];
list($name, $function) = split(':', $go);
if ($function == "Deleted") {
DELETE CODE
} else if ($function == "Entered Edit Mode") {
EDIT PAGE CODE
}
} else {
echo "Invalid Input Type";
}
?>



<input type="radio" value="$dirArray[$index]:Entered Edit Mode" name="action" />
<input type="radio" value="$dirArray[$index]:Deleted" name="action" />

Nile
05-12-2009, 03:13 AM
Great! Glad to see it worked.