SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot kemp's Avatar
    Join Date
    Aug 2004
    Location
    Campinas
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    One checkbox, two functions

    Hi everyone!

    I have a table that lists results from a SQL query. Each result can be selected by a checkbox, like this:



    With the selected items, you can do more than one thing; depending on what the user chooses, the page is directed to one PHP script. The PHP script then needs to know each lines were selected.

    How can I do this? It's supposed to work just like webmails and phpMyAdmin.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is this a JavaScript question?

    You just need to use PHP to check which name/value pairs appear in the $_POST or $_GET array and then do the action for whichever button was clicked.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2005
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <form id="formSQL" action="" method="get">
    	...
    	<button type="submit" onclick="document.getElementById('formSQL').action = 'editar.php';">Desativar</button>
    	<button type="submit" onclick="document.getElementById('formSQL').action = 'desativar.php';">Editar</button>
    	...
    </form>

  4. #4
    SitePoint Zealot kemp's Avatar
    Join Date
    Aug 2004
    Location
    Campinas
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Maian
    HTML Code:
    <form id="formSQL" action="" method="get">
    	...
    	<button type="submit" onclick="document.getElementById('formSQL').action = 'editar.php';">Desativar</button>
    	<button type="submit" onclick="document.getElementById('formSQL').action = 'desativar.php';">Editar</button>
    	...
    </form>

    That's basically what I was thinking. Thanks Maian

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem with doing it like that is you require JavaScript to be enabled.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  6. #6
    SitePoint Zealot kemp's Avatar
    Join Date
    Aug 2004
    Location
    Campinas
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz
    The problem with doing it like that is you require JavaScript to be enabled.
    That's true. But I din't understand how to do it in the way you described earlier. How am I gonna know wich button was clicked if both are on the same form?

  7. #7
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Several browsers include the name/value pair of the submit button that was clicked to submit the form with the rest of the name/value pairs.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •