Re: Syntax Help....
"Ross M. Greenberg" <greenber-at-catskill.net> wrote in message
news:vhvh9in3gn lj01@corp.super news.com...[color=blue]
>
> "Zac Hester" <news@planetzac .net> wrote in message
> news:3f1f4c41$1 @news.enetis.ne t...[color=green]
> >
> >
> > For now, add another couple of debugging lines like this:
> > alert("Old Value: "+formref.shipp ing_1.value);
> > formref.shippin g_1.value = "12.34";
> > alert("New Value: "+formref.shipp ing_1.value);[/color]
>
> Tried it. Why would I get an "undefined" on the first alert?[/color]
This is saying something. JavaScript doesn't really care if you make up
object properties on the fly, so my guess is that you were never assigning
the value to the form object's property. You are referencing some other
(new) object. Here's what you can try:
Copy out your form and JavaScript associated to that form. Put all of your
JavaScript in the "head" of your document. Here's a quick page I wrote up
that works on my browser. Try copying this into a new HTML document and see
what happens.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JavaScri pt Form Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function update_form(for mref, debug) {
if(debug) {
alert('Initial Value: '+formref.shipp ing_1.value);
}
formref.shippin g_1.value = "321";
if(debug) {
alert('Assigned Value: '+formref.shipp ing_1.value);
}
//Keep it from submitting for now.
return(false);
}
</script>
</head>
<body>
<h3>JavaScrip t Form Test</h3>
<form name="test" id="testid" action="tester. php"
method="post" onsubmit="retur n update_form(thi s, true);">
<input type="text" name="shipping_ 1" value="123" />
<input type="submit" name="submit_bu tton" value="Submit" />
</form>
</body>
</html>
Hopefully, this is enough that you can take it an add your own form
elements. Paste the end result into your page and see if it still works.
Also, I wrote this little function that might be of use:
function show_form_data( formref) {
var i, buffer = '';
for(i = 0; i < formref.element s.length; i++) {
buffer += formref.element s[i].name
+': '+formref.eleme nts[i].value+"\n";
}
return(confirm( "Form Data about to Be Submitted:\n\n"
+buffer+"\n\nPr oceed?"));
}
If you call this from your form with an onsubmit="retur n
show_form_data( this);", this will show you a list of all the data in a form.
[color=blue][color=green]
> >
> > Also, if your site is hosted on a server running PHP, I have a script[/color][/color]
that[color=blue][color=green]
> > might be useful. It's very simple:[/color]
>
> No PHP. Sigh. Script in tester.txt on the site.
>[/color]
You'll need to name it tester.php for it to work on a PHP-enabled host.
Let me know how it turns out,
Zac
"Ross M. Greenberg" <greenber-at-catskill.net> wrote in message
news:vhvh9in3gn lj01@corp.super news.com...[color=blue]
>
> "Zac Hester" <news@planetzac .net> wrote in message
> news:3f1f4c41$1 @news.enetis.ne t...[color=green]
> >
> >
> > For now, add another couple of debugging lines like this:
> > alert("Old Value: "+formref.shipp ing_1.value);
> > formref.shippin g_1.value = "12.34";
> > alert("New Value: "+formref.shipp ing_1.value);[/color]
>
> Tried it. Why would I get an "undefined" on the first alert?[/color]
This is saying something. JavaScript doesn't really care if you make up
object properties on the fly, so my guess is that you were never assigning
the value to the form object's property. You are referencing some other
(new) object. Here's what you can try:
Copy out your form and JavaScript associated to that form. Put all of your
JavaScript in the "head" of your document. Here's a quick page I wrote up
that works on my browser. Try copying this into a new HTML document and see
what happens.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JavaScri pt Form Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function update_form(for mref, debug) {
if(debug) {
alert('Initial Value: '+formref.shipp ing_1.value);
}
formref.shippin g_1.value = "321";
if(debug) {
alert('Assigned Value: '+formref.shipp ing_1.value);
}
//Keep it from submitting for now.
return(false);
}
</script>
</head>
<body>
<h3>JavaScrip t Form Test</h3>
<form name="test" id="testid" action="tester. php"
method="post" onsubmit="retur n update_form(thi s, true);">
<input type="text" name="shipping_ 1" value="123" />
<input type="submit" name="submit_bu tton" value="Submit" />
</form>
</body>
</html>
Hopefully, this is enough that you can take it an add your own form
elements. Paste the end result into your page and see if it still works.
Also, I wrote this little function that might be of use:
function show_form_data( formref) {
var i, buffer = '';
for(i = 0; i < formref.element s.length; i++) {
buffer += formref.element s[i].name
+': '+formref.eleme nts[i].value+"\n";
}
return(confirm( "Form Data about to Be Submitted:\n\n"
+buffer+"\n\nPr oceed?"));
}
If you call this from your form with an onsubmit="retur n
show_form_data( this);", this will show you a list of all the data in a form.
[color=blue][color=green]
> >
> > Also, if your site is hosted on a server running PHP, I have a script[/color][/color]
that[color=blue][color=green]
> > might be useful. It's very simple:[/color]
>
> No PHP. Sigh. Script in tester.txt on the site.
>[/color]
You'll need to name it tester.php for it to work on a PHP-enabled host.
Let me know how it turns out,
Zac
Comment