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!

Extracting a value from an input box using a variable input box nam.

Status
Not open for further replies.

Triton001

Programmer
Jan 17, 2002
8
US
Hi,

Can anyone help me figure this out. I'm passing a String variable to a function that I want to use in the dot notation string to get the value of the input box.

EXAMPLE:
function calcext(price, boxname)
{
var exttotal = document.order.+'boxname'+.value * price;
document.order.extTot0.value = format(exttotal,2);
}

The "boxname" value/variable I'm passing into the function is a string and all I want to do is append it to the string reference of theinput box, like this.
document.order.+'boxname'+.value

I thought I could just append the value to the string but when I run the calculation it just returns NAN.

Ultimately all I need is to to get the value of an input box so I can calculate 2 numbers. But I can't hard code the dot notation string that references the input box I want to calculate.

Anyone able to help?

Mike
Mikecook@net-ins.com


 
document.order[boxname].value

no "." before '[" --------------------------------------------------
Goals are dreams with deadlines
 
Thanks for responding
When I use the following index "document.order[boxname].value" it gives me an error that is telling me this is not an object...

Error Message:
document.order[...].value is not an object

Anything else to try?

Mike
 
triton001,
the following sample code worked for me:

<html>
<head>
<title>Box Name</title>

<script langauge=&quot;javascript&quot;><!--
var ttl

function calc (price, item) {
ttl = document.frm[item].value * price
alert(&quot;price is &quot; + price)
alert(&quot;item is &quot; + item)
alert(&quot; and the total is &quot; + ttl)
}
//-->
</script>

</head>

<body>
<form name=&quot;frm&quot;>
Item One Quantity: <input type=&quot;text&quot; name=&quot;OneQ&quot;> <input type=&quot;button&quot; value=&quot;calculate for item one&quot; onClick=&quot;calc(15,'OneQ')&quot;> price = $15<p>
Item Two Quantity: <input type=&quot;text&quot; name=&quot;TwoQ&quot;> <input type=&quot;button&quot; value=&quot;calculate for item two&quot; onClick=&quot;calc(10,'TwoQ')&quot;> price = $10<p>
</form>

</body>
</html>

does that help any? --------------------------------------------------
Goals are dreams with deadlines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top