Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to pass variables into AJAX request?

    Hello, Dear Guys how to pass variables into AJAX request,

    I have this div in the PHP page:
    Code:
    <div id="display_poll"></div>
    and this is the AJAX_common.php code:
    Code:
    					 <table width="125" border="0" cellspacing="0" cellpadding="0">
    <form method="post" action="ajax_common.php">
     <tr> 
        <td class="cell3">question</td>
      </tr>
     <tr>
       <td class="cell4"><input type="radio" name="option_id" value="1">option 1</td>
     </tr> <tr>
       <td class="cell4"><input type="radio" name="option_id" value="2">option 2</td>
     </tr> <tr>
       <td class="cell4"><input type="radio" name="option_id" value="3">option 3</td>
     </tr> <tr>
     <td class="cell4">
     <input type="hidden" name="action" value="vote">
     <input type="hidden" name="poll_ident" value="22">
     <input type="submit" class="button" value="vote">
      <br>
    <span class='click_span' onclick="MakeRequest('ajax_common.php?action=results&amp;poll_ident=22', 'display_poll')">results</span>
       </td>
      </tr>
     </form>
    </table>
    when I select an option then submit the page it will reload again, is there a way to switch automatic the div and get the poll result instead of poll main form

    regards heaps

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi there what you need to do is on your submit button ,,, run a function and from the function call a javascript function that will talk to your to your php page and then return the content that will go into your div

    you use the GetXmlHttpObject() to talk to your php page

    so in your return javascript ajax will be:

    document.getElementById('display_poll').innerHTML=xmlHttp.responseText;

    and this will replace the inner content... you dont need to post..
    <marquee>thanks</marquee>

  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello chris_angell,

    I already have <div id="display_poll"></div> and the table of AJAX_common.php has loaded and published to display_poll like document.getElementById('display_poll').innerHTML=xmlHttp.responseText;

    for sure when you vote the original form should be change to poll result and replace the original form.

    if you have a small example much better,

    Regards

  • #4
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    snake_eyes
    The <div id="display_poll"></div> worked perfectly for my uses. Thanks a ton.

    - Los Angeles DUI Lawyer
    Last edited by mrsylves; 10-19-2009 at 09:30 PM. Reason: error

  • #5
    New Coder
    Join Date
    Mar 2007
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hehehe

    it is too late my dear, I finished this project since 2 years and I forget its code


  •  

    Posting Permissions

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