SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow How do you submit text from a page using ajax?

    I need have put a mysql record id number onto my webpage. I now need to submit that id when the form is submitted so that the correct id is updated.

    // Here is where my id goes.
    <span id="id1">*** the id number ***</span>



    // now I need to know how to send the id number
    <input type="submit"
    name="submitit"
    onClick="valbutton(***how do I put my id number here??***);
    return false;"
    value="Validate" />


    How do I submit the id?
    Thanks for any help.
    Steven.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    passing values

    I don't think you want to use javascript for this. Got PHP?
    PHP Code:
    // Here is where my id goes.
    <span id="id1"><?php echo $id_number?></span>


    // now I need to know how to send the id number
    <input type="submit"
    name="submitit"
    onClick="valbutton(<?php echo $id_number?>);
    return false;"
    value="Validate" />

  3. #3
    I ♥ PHP
    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could create a hidden field on the fly using Javascript, and in doing so set the value of the hidden field to be the same as the id number in the span? This would pass the id number to the page that handles the form?

    Regards,
    Jordan

  4. #4
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by J Windebank
    You could create a hidden field on the fly using Javascript, and in doing so set the value of the hidden field to be the same as the id number in the span? This would pass the id number to the page that handles the form?

    Regards,
    Jordan
    Thanks for the reply, I am enticed by the reply but being new to JS I am not altogether sure I understand.
    Is this the idea?

    // if there is an id value on my page...
    if (document.getElementById("id1").value)
    {
    // ...then make the hidden field value the same as this value
    document.getElementById("id").value = document.getElementById("id1").value;
    }

    // use the hidden feild value when submitting the onclick

  5. #5
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stevenodonnell
    Thanks for the reply, I am enticed by the reply but being new to JS I am not altogether sure I understand.
    Is this the idea?

    // if there is an id value on my page...
    if (document.getElementById("id1").value)
    {
    // ...then make the hidden field value the same as this value
    document.getElementById("id").value = document.getElementById("id1").value;
    }

    // use the hidden feild value when submitting the onclick
    Thanks for the response Mittineague, but wouldn't that defeat the purpose of using ajax? Every time I change the php variable (in this case the id) the page would need refreshed.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    MySQL

    Quote Originally Posted by stevenodonnell
    I need have put a mysql record id number onto my webpage.
    I was thinking that when you put the record # into the page you could put it into the onclick argument at the sime time. I'm still not sure how you're getting the # for the first page load, but if you want to use AJAX to send the # back to the server a GET or POST var from a hidden input would work.


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
  •