473,326 Members | 2,813 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,326 software developers and data experts.

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

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
3 1389
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
5
by: Gregor Rot | last post by:
Hi, if i have this code: <form><input type=text name="id1"></form> then with javascript i can reference this with this.form.id1, how can i reference something like this: <table> <tr...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
10
by: Kelly | last post by:
Can anyone tell me what I'm doing wrong here? ================================== <html> <head> <title>Test Form</title> <script language="JavaScript" type="text/javascript"> </head>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.