Error : undefined function

D

design

Greetings,

I have defined functions using instructions found in O'Reilly's
"JavaScript: The Definitive Guide 4th Edition." When I call on the
functions I get this type of error message.

Error: test is not defined

There is a second error message that only shows with up with some calls
to test(). Since the left-hand operand is an object property I don't
know what I'm doing wrong here.

Error: invalid assignment left-hand side
Source Code:
document.uf-s.shipping.value = 0;

<script language="JavaScript">
function test(){
alert('Function call succeeded');
document.uf-s.shipping.value = 0;
}
</script>

<form name="uf-s" onsubmit="return test();">
<input type="hidden" name="shipping" value="19.00">
<input type="submit">
</form>


Thank you to everyone who can help with this problem.

Mountain Man
 
T

Thomas 'PointedEars' Lahn

Error: invalid assignment left-hand side
Source Code:
document.uf-s.shipping.value = 0;
^
The minus character (`-') is, well, the minus operator
(outside of literals, as here).
<script language="JavaScript">

function test(){
alert('Function call succeeded');
document.uf-s.shipping.value = 0;
}

Proper indentation helps.
</script>

<form name="uf-s" onsubmit="return test();">

document.forms['uf-s'].elements['shipping'].value = 0;

And the `action' attribute value is missing for Valid HTML.

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


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
function test(){
alert('Function call succeeded');
document.uf-s.shipping.value = 0;
}
[...]
<form name="uf-s" onsubmit="return test();">

document.forms['uf-s'].elements['shipping'].value = 0;

Even better:

function test(f)
{
// ...
f.elements['shipping'].value = 0;
f.submit();
return false;
}

<form action="..." name="uf-s" onsubmit="return test(this);">

This should make sure that, if client-side script support is present,
the form is not submitted before the element's value is "0", as that
appears to be your intention.


PointedEars
 
D

design

Thank you for your help PointedEars. Unfortunately, I get "Error:
welcome is not defined" even with the trivial function below. And the
"action" attribute of my real world form has been set, I just
eliminated that detail from the code example for the sake of
simplicity.

<script language="JavaScript">
function welcome(){
alert('Hello World');
}
</script>

Mountain Man
 
T

Thomas 'PointedEars' Lahn

Thank you for your help PointedEars.

You're welcome, however it would be appreciated if you posted according to
the well-established set of behavioral recommendations here, such as to
quote what you are referring to and to provide attribution for quoted
material.

Unfortunately, I get "Error: welcome is not defined" even with the
trivial function below. And the "action" attribute of my real world
form has been set, I just eliminated that detail from the code example
for the sake of simplicity.

Then I suggest you use ellipsis (`...') to avoid comments on it. Too many
people do not know how to write Valid markup and about the ramifications of
invalid markup regarding the execution of script code that is operating on
that.
<script language="JavaScript">

The `type' attribute is still missing, the `language' attribute is
deprecated, in Valid HTML 4.
function welcome(){
alert('Hello World');
}

This is syntactically correct JS/ECMAScript code. The error
must be somewhere else, perhaps in the calling statement.
</script>

Just to be sure: You did not include that same code in a script file,
say foo.js, and included that with

<script ... src="foo.js"></script>

in your HTML document, did you? Otherwise it would explain that error
message since markup outside of literals does not belong into a script
file.


PointedEars
 
L

Lee

(e-mail address removed) said:
Thank you for your help PointedEars. Unfortunately, I get "Error:
welcome is not defined" even with the trivial function below. And the
"action" attribute of my real world form has been set, I just
eliminated that detail from the code example for the sake of
simplicity.

<script language="JavaScript">
function welcome(){
alert('Hello World');
}
</script>

Don't eliminate so much detail that we can't identify your
problem. The code you posted works perfectly, although the
script tag should have a "type="text/javascript" attribute.

The error is somewhere else on your page, or in the placement
of the script block within your page.

<html>
<head>
<script language="JavaScript">
function welcome(){
alert('Hello World');
}
</script>
</head>
<body onload="welcome()">
works
</body>
</html>
 
M

Marino Guerieri

Greetings,

I have defined functions using instructions found in O'Reilly's
"JavaScript: The Definitive Guide 4th Edition." When I call on the
functions I get this type of error message.

Error: test is not defined

There is a second error message that only shows with up with some calls
to test(). Since the left-hand operand is an object property I don't
know what I'm doing wrong here.

Error: invalid assignment left-hand side
Source Code:
document.uf-s.shipping.value = 0;

<script language="JavaScript">
function test(){
alert('Function call succeeded');
document.uf-s.shipping.value = 0;
}
</script>

<form name="uf-s" onsubmit="return test();">
<input type="hidden" name="shipping" value="19.00">
<input type="submit">
</form>


Thank you to everyone who can help with this problem.

Mountain Man

If you need to get some value, you must write that code whitout document
(examle form_name.name.value)
 
T

Thomas 'PointedEars' Lahn

Marino said:
(e-mail address removed) says...
Error: invalid assignment left-hand side
Source Code:
document.uf-s.shipping.value = 0;
[...]

If you need to get some value, you must write that code whitout document
(examle form_name.name.value)

Utter nonsense. It is the operator character that causes the problem.


PointedEars
 
R

Randy Webb

Marino Guerieri said the following on 11/27/2005 5:20 AM:
Greetings,

I have defined functions using instructions found in O'Reilly's
"JavaScript: The Definitive Guide 4th Edition." When I call on the
functions I get this type of error message.

Error: test is not defined

There is a second error message that only shows with up with some calls
to test(). Since the left-hand operand is an object property I don't
know what I'm doing wrong here.
document.uf-s.shipping.value = 0;
document.forms['uf-s'].elements['shipping'].value



If you need to get some value, you must write that code whitout document
(examle form_name.name.value)

Who taught you that garbage?
Besides, your syntax is IE-only unless you are passed a reference to
form_name and in this case it isn't.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top