-
Newbie help with javascript code?
I'm just now starting to mess around with javascript, and I wrote this code as a calculator to figure what price bracket customers would be in for color copies. It would return a "price per copy" in a field when the customer entered their quantity. I can't get the code to do anything though. I might be way off... Thanx in advance for the help?
<HTML>
<HEAD>
<TITLE>Color Copies Calculator</TITLE>
<SCRIPT LANGUAGE="Javascript"><!-- Hide from old browsers
function figure(){
var quantity = document.form.count.value();
var return = document.form.pricepercopy.write();
if (quantity <= 50) return .69;
if (quantity <= 100) return .42;
if (quantity <= 150) return .37;
if (quantity <= 300) return .33;
if (quantity <= 500) return .29;
}
// Stop hiding from old browsers -->
</SCRIPT>
</HEAD>
<BODY>
<P><FORM NAME="form">
<INPUT TYPE="TEXT" NAME="count" SIZE="24"><BR>
<INPUT TYPE="TEXT" NAME="pricepercopy" SIZE="24"><INPUT TYPE="SUBMIT" VALUE="Get My Price" onClick="figure()"></P></FORM>
</BODY>
</HTML>
-
First, this is a java forum. Not Javascript.
try removing the "<!-- Hide from old browsers" and " -->"
Also put an "alert('here');" at the top of the function.
Is there a JS error showing up (look at the bottom left of the browser).
-
oops....do I move it?
do I put the alert above the function or right above the variable?
and there is no error showing up...
-
Will the logic of this work? If you have a count less than 100, isn't that count less than the higher quatity cut-off's, too? So which value is the one you want?
If this is where your script is not working, determine whether the count is larger than a lower value AND less than the upper level then you know you are in a specific "range" ...
-
above the variable
alert('here');
var quantity = document.form.count.value();
-
Now that I look at it more.
Don't use return as a var.
And your function looks like it returns the number but does nothing with it.
-
so with those changes, I'm still not getting anything?
what does the (alert) do?
<HTML>
<HEAD>
<TITLE>Color Copies Calculator</TITLE>
<SCRIPT LANGUAGE="Javascript">
function figure(){
alert('here');
var quantity = document.form.count.value();
var return = document.form.pricepercopy.write();
if (quantity <= 50 && >= 0) return .69;
if (quantity <= 100 && >= 50) return .42;
if (quantity <= 150 && >= 100) return .37;
if (quantity <= 300 && >= 150) return .33;
if (quantity <= 500 && >= 300) return .29;
}
</SCRIPT>
</HEAD>
<BODY>
<P><FORM NAME="form">
<INPUT TYPE="TEXT" NAME="count" SIZE="24"><BR>
<INPUT TYPE="TEXT" NAME="pricepercopy" SIZE="24"><INPUT TYPE="SUBMIT" VALUE="Get My Price" onClick="figure()"></P></FORM>
</BODY>
</HTML>
-
so i was using "return" as a variable to write to the "pricepercopy" field.... how would I make it right that value to the "pricepercopy" field?
-
alert will pop up a message box. since it is at the top and it never appears - that means your function is not being called OR it can't be called because the javascript is invalid or the calling of it is invalid.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|