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 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2007
    Location
    Seattle, WA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Javascript Vars w/ Ajax

    I'm trying to compile an update form on my website from a regular, button-style-update page.

    i've got the ajax code .. in coding from a tutorial you could say, but I'm confused -- How do I fetch variables from a form, and how would I configure them in a "get" style string?

    --Thiscolddecembe(r)

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts

    Basic Idea:

    You would reference the form elements with

    document.formName.elementName.value or document.forms[0].elementName.value or document.getElementById(elementId).value

    And you build a big string

    var str = "?foo=" + document.getElementById(elementId).value + "&bar=" + document.getElementById(elementId2).value;

    ....open("yourURL.php" + str,.....)

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Another option is to pass the form data as arguments to a function.

    example:
    Code:
    <script type="text/javascript">
    function blah(fname,lname) {
    alert('Hello '+fname+' '+lname);
    var first = fname;
    var last = lname;
    }
    </script>
    <form id="frm" method="post" action="">
    <input type="text" id="firstname" value="">
    <input type="text" id="lastname" value="">
    <input type="button" id=".btn" value=" Submit " onclick="blah(firstname.value,lastname.value)">
    </form>


  •  

    Posting Permissions

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