Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hey everyone, here is my situation.

Status
Not open for further replies.

shu745

Programmer
May 14, 2001
79
US
Hey everyone, here is my situation. I have my child window submitting select-list form data to my parent window just fine. BUT before I send it I want to manipulate(add) that data. Here is my code (child window):

<script name=&quot;javascript&quot;>
function GetValues(value1,value2,value3,value4) {
value1 = data.One.value;
value2 = data.Two.value;
Total = value1 + value2;
opener.document.myForm.Total.value = Total;
self.close(); }
</script>
</head>
<body onload=&quot;&quot;>
<form name=&quot;data&quot;>
<p>
<select name=&quot;One&quot;>
<option value=&quot;1&quot; selected>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
</select>
<br>
<br>
<select name=&quot;Two&quot;>
<option value=&quot;5&quot; selected>5</option>
<option value=&quot;10&quot;>10</option>
<option value=&quot;15&quot;>15</option>
</select>
<input type=&quot;submit&quot; name=&quot;calc&quot; value=&quot;calc&quot; onclick=&quot;GetValues();&quot; >
</form>

The thing is that the value of Total ends up concatenating string values and not seeing them as numbers. ie. So 5+1=51 instead of 6!

Any help is greatly appreciated!!

Thanks in adavance.

-Shu
 
Please would you try this...


Code:
Instead of..  Total = value1 + value2

Use ...         Total = (value1-0) + (value2-0)


I think you need to force value1 and value2 to have numeric, rather than string identities, and you can do this by performing a numeric function on them.

Haven't tried it for you, just a guess.

Regards,
Graham
 
i wrote a really big calculator in javascript is if you have4 any problems with logic of your calculator or anything like that email me

i spent weeks working on a script that is now wasted and just want to share it.

eskylidder@hotmail.com
 
try:

value1 = eval(data.One.value);
value2 = eval(data.Two.value);

with eval() you can read out a string as if it were js-code. a few days ago i wrote a little script to sum two numbers (just to try if i had understand the basic things in js). first i had the same problem and 3+1 was 31, but it works fine with eval(), so now 3+1 is 4 *g*

greetz
askey
 
Thanks everyone! I tried the eval() function and it worked out. I really appreciate all your responses. I hope I can return the favor sometime.

-Shu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top