-
July 29th, 2009, 10:48 AM #1Junior 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:
Then on the submit button I've used a simple image with the href "javascriptCode:function payform() { var total = first+amount; document.forms.pl_pay.write('<input type="hidden" name="totalamm" value="'+total+'">'); document.forms.pl_pay.submit(); }
ayform();" (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...
-
July 30th, 2009, 12:44 PM #2
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
-
beginner javascript, trying to put objects in array stupidity
By Saulg in forum Webmastering and ProgrammingReplies: 0Last Post: March 23rd, 2009, 10:34 AM -
Beginner in Javascript, need help with Firefox add-on
By gschmidt in forum Webmastering and ProgrammingReplies: 2Last Post: October 29th, 2008, 06:54 PM -
Beginner in Javascript I need help!!
By overdosed20 in forum Webmastering and ProgrammingReplies: 6Last Post: June 24th, 2008, 11:34 AM -
Beginner Javascript question
By James Engle in forum Webmastering and ProgrammingReplies: 0Last Post: April 21st, 2008, 10:43 PM -
Beginner, javascript code help!
By snikker74 in forum Webmastering and ProgrammingReplies: 4Last Post: April 4th, 2008, 11:08 AM



LinkBack URL
About LinkBacks



Reply With Quote

About 18 months ago, I went pure conspiracy theorist and pretty much paranoid about everything regarding electronics due to a smartphone app I was coding. Stopped coding the app and sold the phone....
Is it OK to spy if its just for...