Post type Submit when radio button clicked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RogerInHawaii
    New Member
    • Jun 2007
    • 13

    Post type Submit when radio button clicked

    I want to effectively do a Post type submit to the very same page when the user clicks on a particular radio button. Of course, I also want it to recognize the click (i.e. checkmarking the radio button) first so the new status of that readio button gets properly Posted.

    How do I do that?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heay, RogerInHawaii.

    What you'll want to do is set the checked property of the radio button, then submit the form. You may also need to change the action of the form.

    [code=html]
    <form id="thePfhorm" action="somepag e.php" method="post">
    <input type="radio" onclick="doClic k(this);" />
    </form>
    [/code]

    [code=javascript]
    function doClick(element ) {
    element.checked = true;
    var pfhorm = document.getEle mentById('thePf horm');
    pfhorm.action = location.href;
    pfhorm.submit() ;
    }
    [/code]

    Comment

    • RogerInHawaii
      New Member
      • Jun 2007
      • 13

      #3
      pbmods,

      Is there a way to do that with just PHP? Can the OnClick call a PHP function and then within the PHP fnction cause a submit to occur?

      Or can the Onclick itself somehow specify a submit?

      - Roger

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Roger.

        Originally posted by RogerInHawaii
        Is there a way to do that with just PHP? Can the OnClick call a PHP function and then within the PHP fnction cause a submit to occur?
        Unfortunately, no. PHP and JavaScript cannot interact. Think about it like this: PHP is server-side, whereas JavaScript is client-side, and the only way to make a server request from JavaScript is (currently) to use AJAX.

        Comment

        Working...