473,386 Members | 1,621 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,386 software developers and data experts.

number confusion

below is the javascript that works ok. but i was wanting to assign a variable directly
and as yet i can not can any on tell me what i am doing wrong surround area in question with caps

[HTML]<script language="JavaScript">
function calculateArea(num1)
{
num2 = num1*2
return num2
}
</script>
</head>
<body>
<form name ="myForm">[/HTML]

THE LINE BELOW HERE IS WHAT I WANT TO REPLACE

put number in this box[HTML]<input type="text" name="num1" value="">
[/HTML]
WHAT I WANT IS SOMETHING LIKE THIS var num1=5; but it does not work?



[HTML]<br><br><br>
<input type="button" value="clik to multiply number by 2"
onClick ="document.myForm.num2.value = calculateArea(num1.value)">
<br/><br><br>

number * 2 will appear here <input name="num2" value="">

</form>
</body> </html>[/HTML]
Feb 25 '07 #1
2 962
dorinbogdan
839 Expert 512MB
I'm not sure what you ask.
Do you want to set num1 directly after user input?
Feb 26 '07 #2
acoder
16,027 Expert Mod 8TB
Just put 5 into the value attribute.
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="num1" value="5"> 
The problem you have is accessing the field value. Use:
Expand|Select|Wrap|Line Numbers
  1. var num1 = document.myForm.num1.value;
Feb 27 '07 #3

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

Similar topics

13
by: Tony Williams | last post by:
I have a form with a number of tab controls. The tab controls are part of 3 sub forms that are based on different tables.Is it possible to stack the tabcontrols as say 3 rows of 5 rather than 1...
17
by: jake1138 | last post by:
Here is a function I have to get a number at the end of a string. I'm posting this in case it proves helpful to someone. Comments are welcome. int getnum(char *str) { char buffer; char *buf...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
37
by: Gregc. | last post by:
G'day I'm trying to work out the number of years since 1970, here is my code: include <stdio.h> #include <time.h> const int SEC_IN_MIN = 60; const int SEC_IN_HOUR = SEC_IN_MIN * 60;
9
by: xparrot1 | last post by:
I know that I can get the SERVER port number like this: HttpContext.Current.Request.ServerVariables My question is how do I get the remote CLIENT port number? Thanks Derek
7
by: itm | last post by:
I have a mail out to send to a group of owners with multiple accounts. I want to limit the number of accounts that print on the first page to 20. I want remaining accounts to print on a second...
22
by: MLH | last post by:
If 3 things can be in one of 2 states, the number of possible combinations is equal to 2^3. But if I have 3 things, 2 of which can be in 2 states and the other in 3 states, what's the simplest...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
18
by: Lie | last post by:
I'm very surprised actually, to see that Python rejected the use of fractional/rational numbers. However, when I read the PEP, I know exactly why the proposal was rejected: People compared...
28
by: DanicaDear | last post by:
I have set up a form to contain customer info. From that form, I have a button "Show Order" that links it to a Order Number form. That order number form contains a subform showing order details...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.