By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,461 Members | 1,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,461 IT Pros & Developers. It's quick & easy.

problems referencing form elements by deriving their name from the value of another element

P: n/a
Hi all whats wrong with this script?

i have named a form text box dynamically using php each row has a
textbox called q101, q102 ... etc and i want to make sure my users dont
input a quantity greater than the value of that box. to know which box
applies to which of the products i have used a radio button which
contains the id of the product which corresponds to the name of the box
when a q is added to the front (javascript seems not to like forn names
that are just numbers).

what im trying to do is get the user to click the radio button submit
the form and have the id of the radio button passed as a variable along
with the letter q to the javascript function which uses this string to
locate the right quantity text box to tell the user if he has selected
too many of the product in question.

javascript seems to have a problem in taking the value of a text box
adding it to a string and using this new combined string value to
reference the name of another form element and check its value.

when i use a constant e.g. q191 instead of the var quantityvariation
(in maxquantity declaration) it works fine, maxquantity is the value of
the textbox that contains the value for quantity.

Any idea how i can get this to work?
<script language="javascript" type="text/javascript">
function validForm(product) {

var variationid = product.order.value;
var quantityvariation = "q" + variationid;
var maxquantity = product.quantityvariation.value;

//0 < 1 is just there for testing

if (0 < 1) {
alert(maxquantity)
product.quantity.focus()
return false
}

}
</script>

Jul 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"libsfan01" <mc******@googlemail.comwrote in
news:11*********************@m73g2000cwd.googlegro ups.com:
Hi all whats wrong with this script?

i have named a form text box dynamically using php each row has a
textbox called q101, q102 ... etc and i want to make sure my users dont
input a quantity greater than the value of that box. to know which box
applies to which of the products i have used a radio button which
contains the id of the product which corresponds to the name of the box
when a q is added to the front (javascript seems not to like forn names
that are just numbers).

what im trying to do is get the user to click the radio button submit
the form and have the id of the radio button passed as a variable along
with the letter q to the javascript function which uses this string to
locate the right quantity text box to tell the user if he has selected
too many of the product in question.

javascript seems to have a problem in taking the value of a text box
adding it to a string and using this new combined string value to
reference the name of another form element and check its value.

when i use a constant e.g. q191 instead of the var quantityvariation
(in maxquantity declaration) it works fine, maxquantity is the value of
the textbox that contains the value for quantity.

Any idea how i can get this to work?
<script language="javascript" type="text/javascript">
function validForm(product) {

var variationid = product.order.value;
var quantityvariation = "q" + variationid;
var maxquantity = product.quantityvariation.value;
var maxquantity = product[quantityvariation];
>
//0 < 1 is just there for testing

if (0 < 1) {
alert(maxquantity)
product.quantity.focus()
return false
}

}
</script>

Jul 13 '06 #2

P: n/a
cheers jim

tried that but it javascript tells me that maxquantity is undefined
when i print its value
Jim Land (NO SPAM) wrote:
"libsfan01" <mc******@googlemail.comwrote in
news:11*********************@m73g2000cwd.googlegro ups.com:
Hi all whats wrong with this script?

i have named a form text box dynamically using php each row has a
textbox called q101, q102 ... etc and i want to make sure my users dont
input a quantity greater than the value of that box. to know which box
applies to which of the products i have used a radio button which
contains the id of the product which corresponds to the name of the box
when a q is added to the front (javascript seems not to like forn names
that are just numbers).

what im trying to do is get the user to click the radio button submit
the form and have the id of the radio button passed as a variable along
with the letter q to the javascript function which uses this string to
locate the right quantity text box to tell the user if he has selected
too many of the product in question.

javascript seems to have a problem in taking the value of a text box
adding it to a string and using this new combined string value to
reference the name of another form element and check its value.

when i use a constant e.g. q191 instead of the var quantityvariation
(in maxquantity declaration) it works fine, maxquantity is the value of
the textbox that contains the value for quantity.

Any idea how i can get this to work?
<script language="javascript" type="text/javascript">
function validForm(product) {

var variationid = product.order.value;
var quantityvariation = "q" + variationid;
var maxquantity = product.quantityvariation.value;

var maxquantity = product[quantityvariation];

//0 < 1 is just there for testing

if (0 < 1) {
alert(maxquantity)
product.quantity.focus()
return false
}

}
</script>
Jul 13 '06 #3

P: n/a
"libsfan01" <mc******@googlemail.comwrote in
news:11**********************@75g2000cwc.googlegro ups.com:
var maxquantity = product.quantityvariation.value;
var maxquantity = product[quantityvariation];
tried that but it javascript tells me that maxquantity is undefined
when i print its value
Works for me in IE and FF.
Jul 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.