Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 01-23-2008, 02:47 AM   #1 (permalink)
Registered User
 
Join Date: Jan 2007
Posts: 108
OS: window XP


javascript question

i completely new to javascript. I have a problem here. I want to get user input number and then sum them and print the total. But the problem is i will get a problem.

Example: 1 + 2 should = 3 but i get 12?

how to plus the number?

Code:
<script language="javascript">

var num1 = prompt("Enter Number here", "Type here");
var num2 = prompt("Enter Number here", "Type here");
var total;

total = num1+num2;

document.write(total);

</script>
Thank
peterjcs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 01-26-2008, 05:55 AM   #2 (permalink)
Registered User
 
Join Date: Jan 2008
Location: Harpers Ferry, WV
Posts: 400
OS: OS X 10.4.x


Re: javascript question

JavaScript Prompt

Quote:
It's important to remember that the value returned by prompt() and subsequently stored in a variable will always be a string data type. This is fine if you are dealing with text, but might present problems to the code if you plan to receive numeric data through prompt(). Javascript provides two functions to convert this string value to a numeric data type; parseInt() and parseFloat().
The parseInt() converts a string to an integer value while parseFloat() parses the string converting it to a floating point number.
ShosMeister is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 01-27-2008, 05:30 PM   #3 (permalink)
Registered User
 
Join Date: Jan 2007
Posts: 108
OS: window XP


Re: javascript question

thank ShosMeister.
peterjcs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 01-28-2008, 03:53 PM   #4 (permalink)
Registered User
 
Join Date: Jan 2008
Location: Harpers Ferry, WV
Posts: 400
OS: OS X 10.4.x


Re: javascript question

np :)
ShosMeister is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-04-2008, 07:14 AM   #5 (permalink)
Registered User
 
Join Date: Apr 2008
Posts: 2
OS: xp


Re: javascript question

I have a similar problem, seen this message and figured it might be a fit to ask for help.

I want to select a checkbox and add the values together, I have it working however if the values are more than 1 for a field it will not work?

See below:

<script language="JavaScript">
<!--
function calculate(what) {
what.answer.value =0;
for (var i=1,answer=0;i<6;i++)
answer += (what.elements['CourseOrder' + i].checked)&(what.elements['CourseOrder' + i].value-0);
what.answer.value = answer;
}
//-->
</script>

<form>
<INPUT type="checkbox" NAME="CourseOrder1" VALUE="1" onclick="calculate(this.form)"><br>
<INPUT type="checkbox" NAME="CourseOrder2" VALUE="1" onclick="calculate(this.form)"><br>
<INPUT type="checkbox" NAME="CourseOrder3" VALUE="1" onclick="calculate(this.form)"><br>
<INPUT type="checkbox" NAME="CourseOrder4" VALUE="1" onclick="calculate(this.form)"><br>
<INPUT type="checkbox" NAME="CourseOrder5" VALUE="1" onclick="calculate(this.form)"><br>

<input type="text" name="answer">

</form>

Suggestions very welcome,

Thanks,

Kevin
sodkgb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-04-2008, 03:26 PM   #6 (permalink)
Registered User
 
Join Date: Jan 2008
Location: Harpers Ferry, WV
Posts: 400
OS: OS X 10.4.x


Re: javascript question

Not sure what you mean "if the values are more than 1 for a field". Are you getting an error? If so, what is it as it seems to work fine from what I can see.

Oh and welcome to the Tech Support Forum.
ShosMeister is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-05-2008, 06:25 AM   #7 (permalink)
Registered User
 
Join Date: Apr 2008
Posts: 2
OS: xp


Re: javascript question

I want to insert different values for example CourseOrder1 value=250

The funny thing is it will not calculate? Instead it just gives an answer of 0?

Thank you for your input,

Kevin
sodkgb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-26-2008, 12:02 AM   #8 (permalink)
Registered User
 
Join Date: May 2007
Location: British Columbia, Canada
Posts: 53
OS: vista


Re: javascript question

Hello folks!

When I execute the following, the i variable value goes straight to 176...but if I take out the 'for' loop statement (and the i variable) it works ok?

function testFunction() {
for(i=0; i<=176; i++) {
setTimeout("Nothing()", 100);
doScroll(i+400,0,176-i,140,0);
}
}

Thanks.
BrentC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 03:00 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85