...

Javascript Vars w/ Ajax

thiscolddecembe
08-11-2007, 07:17 PM
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)

A1ien51
08-12-2007, 04:05 AM
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

rwedge
08-12-2007, 06:21 AM
Another option is to pass the form data as arguments to a function.

example:<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum