473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem with referring to form elements

Expand|Select|Wrap|Line Numbers
  1. function calculate(){
  2.  
  3. number= parseInt(numberof);
  4. var price=4;
  5.  
  6. total=price*number;
  7.  
  8. alert("Your total is $" + total);
  9. return true;
  10. };

==

here's the whole code:
[HTML]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">

<body>
<script language="Javascript" type="text/javascript">

function validate()
{

if (document.calcOrder.firstname.value.length<1){aler t("Oops you forgot your first name."); return false;}

if (document.calcOrder.lastname.value.length<1){alert ("Oops you forgot your last name."); return false;}
if (document.calcOrder.street.value.length<6) {alert("Oops that doesn't look like an address."); return false;}

return true;
}

function calculate(){

number= parseInt(numberof);
var price=4;

total=price*number;

alert("Your total is $" + total);
return true;
};







</script>

<title> Widgeteria Order Form</title>
<form name="calcOrder" action="mailto:orders@widgeteria.com"
enctype="text/plain" method="POST"
onSubmit="return validate(this)";"return calculate(this)";>
<h2> Thanks for Ordering From Widgeteria!</h2>
<h4> We sell at a loss and make it up on volume <h4>
<p>First Name: <input type ="TEXT" name="firstname" size="20">
Last Name:<input type ="TEXT" name="lastname" size="40">
<p>Street Address:<input type ="TEXT" name="street" size="75">
<p>City:<input type= "TEXT" name="city" size="20">
State:<select name="state" SIZE=4>
<option value="AL" SELECTED>AL
<option value="AK">AK
<option value="AZ">AZ
<option value="AR">AR
<option value="CA">CA
<option value="CO">CO
<option value="CT">CT
<option value="DE">DE
<option value="DC">DC
<option value="FL">FL
<option value="GA">GA
<option value="GU">GU
<option value="HI">HI
<option value="ID">ID
<option value="IL">IL
<option value="IN">IN
<option value="IA">IA
<option value="KS">KS
<option value="KY">KY
<option value="LA">LA
<option value="ME">ME
<option value="MD">MD
<option value="MA">MA
<option value="MI">MI
<option value="MN">MN
<option value="MO">MO
<option value="MT">MT
<option value="NE">NE
<option value="NV">NV
<option value="NH">NH
<option value="NJ">NJ
<option value="NM">NM
<option value="NY">NY
<option value="NC">NC
<option value="ND">ND
<option value="OH">OH
<option value="OK">OK
<option value="OR">OR
<option value="PA">PA
<option value="PR">PR
<option value="RI">RI
<option value="SC">SC
<option value="SD">SD
<option value="TN">TN
<option value="TX">TX
<option value="UT">UT
<option value="VT">VT
<option value="VA">VA
<option value="VI">VI
<option value="WA">WA
<option value="WV">WV
<option value="WI">WI
<option value="WY">WY
</select>



Zip:<input type= "TEXT" name="zip" size="10">
<p></br>



Widgets are $4. How many would you like?:<input type ="TEXT" name="numberof" size="3">

<p></br>

<input type="SUBMIT" name=senditin value="Submit Order">
<input type="RESET" name=startitover value="Reset Form">
<input type="BUTTON" name=calculate value="Get your total" onClick = "return calculate()">

</form>


</body>


</html>[/HTML]
Mar 15 '08 #1
1 1194
gits
5,390 Expert Mod 4TB
you don't refer the value correctly. either use

Expand|Select|Wrap|Line Numbers
  1. document.forms['calcOrder'].elements['numberof'].value
  2.  
or give your 'numberof'-field an id and use the following:

Expand|Select|Wrap|Line Numbers
  1. function calculate() {
  2.     var n = document.getElementById('the_id_you_gave');
  3.     var num = parseInt(n.value);
  4.     var price = 4;
  5.  
  6.     var total = price * num;
  7.  
  8.     alert("Your total is $" + total);
  9.     return true;
  10. }
  11.  
kind regards
Mar 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
6
by: james | last post by:
CAn Some one please help when this scrip runs it does not enter the data from my forms, it just says where each feild should be. I have tested it using google address and it appears to work just...
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
3
by: MickG | last post by:
Does anyone know how I can fix the code below to work in Firefox,it works perfectly well in IE, the problem is that I have to use Firefox for this assignment. Thankyou Michael <html>...
8
by: wl | last post by:
Hi, I have a radiobutton group in HTML in a form: Sex: <input type="radio" name="Sex" value="male">Male <input type="radio" name="Sex" value="female">Female <input type="radio" name="Sex"...
9
by: Marc | last post by:
Okay, here's the problem - I have 3 radio buttons, and 11 check boxes (which are disabled by default). I have the javascript below which when the last radio button is clicked, enables the...
5
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything...
29
by: Richard Lionheart | last post by:
Hi All, I've taken the advice of a few people and managed to cobble together an HTML 4.01 Strict-compliant document (according to the W3C Validation Service), but the way I try to pass a...
5
by: bspittles | last post by:
Can anyone tell me why the following script doesn't work in Firefox 1.5 (not sure about other versions) when it works fine in IE6 and Netscapes 7.1? Almost as importantly ;) can ayone tell me how...
4
by: Neil | last post by:
Having trouble with inserting a record into a table. It's a list of names. But, for some reason, it won't take a particular name. When a user tries to enter a name into the table, the system hangs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.