Results 1 to 17 of 17

Thread: Two buttons

Hybrid View

  1. #1
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256

    Two buttons

    How can I do something like this:

    Code:
    <form>
    Do you want to delete blah?<br>
    <input type="submit" value=" Yes "><input type="submit" value=" No ">
    </form>
    So that I can have two buttons that submit the for, but each has a differen't value?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 02
    Posts
    616
    I would think you could but I normally do this:

    PHP Code:
    <form action="?" method="post">
    <input type="hidden" name="action" value="delete" />
    <input type="hidden" name="id" value="<?php echo $_REQUEST['id']; ?>" />
    Do you want to delete blah?<br>
    <input type="submit" value=" Yes "><input type="button" value=" No " onClick="history.back();">
    </form>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    hmm...it'll work for now Thanks
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 99
    Posts
    1,290
    you could do somehting like this

    Code:
    <form action="page.php" method="post">
    Do you want to delete blah?<br>
    <input type="button" value=" Yes " name="yes" onClick="this.document.submit();">
    <input type="button" value=" No " name="no" onClick="this.document.submit();">
    </form>
    then in your page.php just check for the variable.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    Wont the yes and no variables both show up no matter which one you press?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 02
    Posts
    616
    no. it acts just like a checkbox, it only shows up if it were picked
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    Frenzied Member
    Join Date
    Nov 99
    Posts
    1,290
    no because the name of each button is what determines the variable. if yes button is not pressed how can the variable get sent?

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    no because the name of each button is what determines the variable. if yes button is not pressed how can the variable get sent?
    Because it is part of the form and has a value set to it (is what I was thinking)

    Thans Matt and phpman.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    It doesn't work...

    I have

    Code:
    <div align="center">
        <form action="' . $CONIFG["scripturl"] . '" method="post">
            <input type="hidden" name="action" value="removeuser">
            <input type="hidden" name="id" value="' . $_REQUEST['user'] . '">
            Are you sure you want to remove user <b>' . $user["usn"] . '</b>?<br><br>
            <input type="button" name="yes" value=" Yes " onClick="document.forms(0).submit();"> 
            <input type="button" name="no" value=" No " onClick="document.forms(0).submit();">
        </form>
    </div>
    For the form, and:

    Code:
    if (isset($_REQUEST['no'])) {
    
    } else {
    
    }
    To check. However, it always goes to the else. It never says 'no' was set?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Frenzied Member
    Join Date
    Nov 99
    Posts
    1,290
    you could put a name in your form and try this

    <form action="' . $CONIFG["scripturl"] . '" method="post" name="form1">
    <input type="button" name="yes" value=" Yes " onClick="document.form1.submit();">
    <input type="button" name="no" value=" No " onClick="document.form1.submit();">

    also is $CONFIG[] coming out ok as the script name?


    how do you know it goes to the else if there is nothing in either one

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    you could put a name in your form and try this

    <form action="' . $CONIFG["scripturl"] . '" method="post" name="form1">
    <input type="button" name="yes" value=" Yes " onClick="document.form1.submit();">
    <input type="button" name="no" value=" No " onClick="document.form1.submit();">

    also is $CONFIG[] coming out ok as the script name?


    how do you know it goes to the else if there is nothing in either one
    What does a form name matter? I never put a name on them and it works fine.

    $CONFIG[] is working fine.

    and their is code in both of them, it was just rather lengthy.

    I guess I'll have to do this another way. Thanks for your help.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Frenzied Member
    Join Date
    Nov 99
    Posts
    1,290
    I thought you just said it wasn't working?

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    I thought you just said it wasn't working?
    It isn't. I said that forms work without the name property.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14
    Frenzied Member
    Join Date
    Nov 99
    Posts
    1,290
    if you notice I change the onclick to work from a forms name. just to see if that was the problem.

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    if you notice I change the onclick to work from a forms name. just to see if that was the problem.
    Still no dice.

    If I do this:

    Code:
      echo "Yes: \"" . $_REQUEST['yes'] . "\"<br>";
      echo "No: \"" . $_REQUEST['no'] . "\"<br>";
    I get:

    Yes: ""
    No: ""
    No matter what button I push. Have you tried doing this on your own to see if it works?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  16. #16
    Frenzied Member
    Join Date
    Nov 99
    Posts
    1,290
    sorry Hobo, I couldn't get it to work either. in theory it should work. but you can use 2 submits.

    <input type="submit" name="yes" value=" Yes " >
    <input type="submit" name="no" value=" No " >

    my appologies.

  17. #17
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 01
    Location
    Michigan
    Posts
    7,256
    It's cool. Thanks for all your help.

    For now, I'm just going to have one of the buttons do history.back();
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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