Results 1 to 6 of 6

Thread: How to pass several values from radio buttons

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default How to pass several values from radio buttons

    Is there a way to set a sub group within a radio's settings? This is the html code I have...

    Code:
    <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.
    Last edited by bluewalrus; 05-12-2009 at 02:54 AM.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    Code:
    <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.
    Jeremy | jfein.net

  5. The Following User Says Thank You to Nile For This Useful Post:

    bluewalrus (05-12-2009)

  6. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Oh, you've got it again. Thanks.

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

    PHP Code:
    <?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";
    }                            
    ?>
    Code:
    <input type="radio" value="$dirArray[$index]:Entered Edit Mode" name="action" />
    <input type="radio" value="$dirArray[$index]:Deleted" name="action" />

  7. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Great! Glad to see it worked.
    Jeremy | jfein.net

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •