Assignment operator does not work

D

design

Greetings,

I have a situation in which an assignment operator isn't working. I'm
trying to reset the value of "document.forms.f.shipping.value" to 0.
I want this new value to be transmitted when the form is submitted.
Unfortunately, the form's shipping element's value remains set at
"19.00."

I have looked for an answer in "JavaScript: the Definitive Guide 4th
edition" and in the clj FAQ. I also reviewd clj posts dating back to
November 14.

<script language="JavaScript" type="text/javascript">

function test(f){
alert('Function call successful');
document.forms.f.shipping.value = 0;
document.forms.f.submit();
return false;
}

</script>

<form name="ufs" onsubmit="return test(ufs);" target="paypal"
action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"
/>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/
x-click-but22.gif" name="submit" />
<input type="hidden" name="shipping" value="19.00" />
</form>
 
M

Matt Kruse

<form name="ufs" onsubmit="return test(ufs);" target="paypal"
action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"
/>

First, you're passing 'ufs' without quotes, which is trying to pass a
variable named 'ufs'. You should quote 'ufs'.
A better approach, though, is to pass a form reference:
<form name="ufs" onsubmit="return test(this);" ...>

Then do:

function test(f){
alert('Function call successful');
f.shipping.value = 0;
return true;
}
 
T

Thomas 'PointedEars' Lahn

I have a situation in which an assignment operator isn't working. I'm
trying to reset the value of "document.forms.f.shipping.value" to 0.
I want this new value to be transmitted when the form is submitted.
Unfortunately, the form's shipping element's value remains set at
"19.00."

And there is most certainly an error message that indicates why.
I am quite sure the FAQ mentions how to retrieve it.
I have looked for an answer in "JavaScript: the Definitive Guide 4th
edition" and in the clj FAQ. I also reviewd clj posts dating back to
November 14.

With me, it is November 20 today. Yours does not strike me as
being an exhaustive search at all. It's not even a week since.
<script language="JavaScript" type="text/javascript">

function test(f){
alert('Function call successful');
document.forms.f.shipping.value = 0;
document.forms.f.submit();
return false;
}

You should have continued the previous thread. At least the above
script code looks like something I have proposed shortly before.
</script>

<form name="ufs" onsubmit="return test(ufs);" target="paypal"
action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"
/>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/
x-click-but22.gif" name="submit" />
<input type="hidden" name="shipping" value="19.00" />
</form>

1. This is most certainly neither (part of) Valid HTML nor XHTML.
Make it Valid HTML 4.01 and remove `language="JavaScript"'.

<http://validator.w3.org/>

2. Your form (element) is named `ufs', not `f'. And the reference
to `ufs' in the intrinsic event handler attribute value is probably
`undefined' as not all UAs make named or IDed elements available
as properties of the Global Object. Pass `this' instead and omit
`document.forms.' in your method.

3. You must not name any form control "submit", otherwise you
overwrote the HTMLFormElement object's submit() method.

4. You should not force new windows or tabs upon users, so you better
remove the `target' attribute.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Matt said:
First, you're passing 'ufs' without quotes, which is trying to pass a
variable named 'ufs'. You should quote 'ufs'.

That would accomplish nothing as he used the argument value like a
reference.


PointedEars
 
R

RobG

Greetings,

I have a situation in which an assignment operator isn't working. I'm
trying to reset the value of "document.forms.f.shipping.value" to 0.
I want this new value to be transmitted when the form is submitted.
Unfortunately, the form's shipping element's value remains set at
"19.00."

I have looked for an answer in "JavaScript: the Definitive Guide 4th
edition" and in the clj FAQ. I also reviewd clj posts dating back to
November 14.

<script language="JavaScript" type="text/javascript">

function test(f){
alert('Function call successful');
document.forms.f.shipping.value = 0;

When using dot notation, the values are treated literally. This is
looking for a form named 'f'. If you want f to be evaluated to get the
value you assigned to it (you attempt to pass the string 'ufs'), then:

document.forms[f].shipping.value = 0;
document.forms.f.submit();
return false;
}

</script>

<form name="ufs" onsubmit="return test(ufs);" target="paypal"

Here you are trying to pass a string[1], so do so:

<form name="ufs" onsubmit="return test('ufs');" target="paypal"


But anyway, why not pass a reference to the form using 'this'?

<form name="ufs" onsubmit="return test(this);" target="paypal"


Now in your function you can do:

f.shipping.value = 0;


since f is now a reference to the form.

[...]

1. I think (without testing) that IE will actually pass a reference to
the form, since it adds names and IDs to the global object, so this may
have worked (but only in IE) without other modification:

f.shipping.value = 0;
 
M

matty

Thomas said:
And there is most certainly an error message that indicates why.
I am quite sure the FAQ mentions how to retrieve it.

LOL and yea "undefined object" helps.
With me, it is November 20 today. Yours does not strike me as
being an exhaustive search at all. It's not even a week since.

Maybe because the poster used a web-based browser and after reading 20
posts per page he figured out his answer was not there?
You should have continued the previous thread. At least the above
script code looks like something I have proposed shortly before.

I totally agree. History helps. Your post is a follow up question to a
previous post, and PointedEars gave you relevant information. Creating
a new post "forgets" the history and that's a bad thing.
 
T

Thomas 'PointedEars' Lahn

matty said:
LOL and yea "undefined object" helps.

I don't think that the FAQ restricts its recommendations to
Internet Explorer because particularly the error messages of
this user agent turn out to be extremely seldom helpful.
Maybe because the poster used a web-based browser and after reading 20
posts per page he figured out his answer was not there?

A "Web-based browser" includes the opportunity to use Google Groups search.


PointedEars
 
M

matty

Thomas said:
No, passing this(!) would break with the current function code.


PointedEars

True, I should have extended my "simple" answer to include the current
function code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top