+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    1

    Javascript beginner needs help with form submissions

     
    I'm a beginner with Javascript, and am curently playing around with forms to see what can and can't be done. I'm a learn by doing kind of bloke!

    I have a form which takes different numbers. It then POST's the information to a simple PHP script which simply echo's whichever value I want it to so I can play with the form to see what works and what doesn't.

    What I'm trying to do is have the form add up two values when you hit the submit button, then POST the answer as one of the hidden form values. This is what I'm trying to do rather than add up the sent values in the receiving PHP file. I can do that already, I wont learn anything from doing that.

    How I've tried going about this at the moment is instead of having the form submit whan hitting the submit button, have it run a function which adds up the values, then submits the form. What actually happens though is that the webpage thinks about it for a bit, then just sits there and does nothing!

    Here's the code I'm using. The form is called pl_pay.

    In the header:

    Code:
    	function payform() {
    	var total = first+amount;
    	document.forms.pl_pay.write('<input type="hidden" name="totalamm" value="'+total+'">');
    	document.forms.pl_pay.submit();
    	}
    Then on the submit button I've used a simple image with the href "javascriptayform();" (obviously that's a : and a p in there, not a poky tongue smiley!)

    So what have I done wrong here? Probably about a hundred things in 4 lines of code...

  2. #2
    Member theGlitch's Avatar
    Join Date
    Jul 2008
    Location
    Boston, MA
    Posts
    185
    Blog Entries
    1
    I my self am still pretty new to JS... but in the AJAX book I'm reading (AJAX for Dummies) they talk about POST. See if the code below helps you out at all:

    function getOptions(scheme)
    {
    var url = "options3.php";

    if(XMLHttpRequestObject) {
    XMLHttpRequestObject.open("POST", url);
    XMLHttpRequestObject.setRequestHeader('Content-Type',
    'application/x-www-form-urlencoded');

    XMLHttpRequestObject.onreadystatechange = function()
    {
    if (XMLHttpRequestObject.readyState == 4 &&
    XMLHttpRequestObject.status == 200) {
    var xmlDocument = XMLHttpRequestObject.responseXML;
    options = xmlDocument.getElementsByTagName("option");
    listOptions();
    }
    }

    XMLHttpRequestObject.send("scheme=" + scheme);

    }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. beginner javascript, trying to put objects in array stupidity
    By Saulg in forum Webmastering and Programming
    Replies: 0
    Last Post: March 23rd, 2009, 10:34 AM
  2. Beginner in Javascript, need help with Firefox add-on
    By gschmidt in forum Webmastering and Programming
    Replies: 2
    Last Post: October 29th, 2008, 06:54 PM
  3. Beginner in Javascript I need help!!
    By overdosed20 in forum Webmastering and Programming
    Replies: 6
    Last Post: June 24th, 2008, 11:34 AM
  4. Beginner Javascript question
    By James Engle in forum Webmastering and Programming
    Replies: 0
    Last Post: April 21st, 2008, 10:43 PM
  5. Beginner, javascript code help!
    By snikker74 in forum Webmastering and Programming
    Replies: 4
    Last Post: April 4th, 2008, 11:08 AM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews