473,795 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 quantityvariati on
(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="javas cript" type="text/javascript">
function validForm(produ ct) {

var variationid = product.order.v alue;
var quantityvariati on = "q" + variationid;
var maxquantity = product.quantit yvariation.valu e;

//0 < 1 is just there for testing

if (0 < 1) {
alert(maxquanti ty)
product.quantit y.focus()
return false
}

}
</script>

Jul 13 '06 #1
3 1433
"libsfan01" <mc******@googl email.comwrote in
news:11******** *************@m 73g2000cwd.goog legroups.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 quantityvariati on
(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="javas cript" type="text/javascript">
function validForm(produ ct) {

var variationid = product.order.v alue;
var quantityvariati on = "q" + variationid;
var maxquantity = product.quantit yvariation.valu e;
var maxquantity = product[quantityvariati on];
>
//0 < 1 is just there for testing

if (0 < 1) {
alert(maxquanti ty)
product.quantit y.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******@googl email.comwrote in
news:11******** *************@m 73g2000cwd.goog legroups.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 quantityvariati on
(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="javas cript" type="text/javascript">
function validForm(produ ct) {

var variationid = product.order.v alue;
var quantityvariati on = "q" + variationid;
var maxquantity = product.quantit yvariation.valu e;

var maxquantity = product[quantityvariati on];

//0 < 1 is just there for testing

if (0 < 1) {
alert(maxquanti ty)
product.quantit y.focus()
return false
}

}
</script>
Jul 13 '06 #3
"libsfan01" <mc******@googl email.comwrote in
news:11******** **************@ 75g2000cwc.goog legroups.com:
var maxquantity = product.quantit yvariation.valu e;
var maxquantity = product[quantityvariati on];
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
4913
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 question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag. I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the...
54
4618
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " + salaryMinLabel.value); } I also have an asp.net object:
4
9303
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 action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
5
5780
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 name="id2"> .. ..
6
2747
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 called "form1", and I have selects called "PORTA", "PORTB" ... etc...
5
1896
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 control2
11
3002
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
2
2136
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. Using Safari,my first iteration the script works fine ( indicating that there are 33 form variables ). When trying another dropdown select value, the
10
2197
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
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.