473,804 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

form.name - dynamically set the name

103 New Member
Hello

I think this is a simple syntax question but I can't seem to find the answer so far...

I want my javascript to collect the value from a form input with the name

nType[731]

It has this name because in PHP this creates an array automatically.

The problem is that the number (731) is dynamic. I know a solution would be to send the number in the function call but I have already sent the number in another form field so it seems wasteful to send it twice.

I have tried the following:

Expand|Select|Wrap|Line Numbers
  1. num=731;
  2. nTypeName="nType["+num+"]";
  3. var v=form.nTypeName.value;
  4.  
...and...

Expand|Select|Wrap|Line Numbers
  1. num=731;
  2. var v=form.nType[num].value;
  3.  
... and ...


Expand|Select|Wrap|Line Numbers
  1. num=731;
  2. var v=form.["nType["+num+"]"].value;
  3.  
Can anyone help?!

Thanks in advance...

Henry
Feb 28 '08 #1
3 1635
henryrhenryr
103 New Member
OK... this always happens.

Someone else posted similar question which answered mine - sorry!

The solution was to reference the "elements" object in the form object.

so I used:

Expand|Select|Wrap|Line Numbers
  1. num=731;
  2. formElements=form.elements;
  3. var v=formElements["nType["+num+"]"].value;
  4.  
Feb 28 '08 #2
ticonetster
1 New Member
OK... this always happens.

Someone else posted similar question which answered mine - sorry!

The solution was to reference the "elements" object in the form object.

so I used:

Expand|Select|Wrap|Line Numbers
  1. num=731;
  2. formElements=form.elements;
  3. var v=formElements["nType["+num+"]"].value;
  4.  
I found this post and was really excited because i cant figure it out myself.

overview
I created a number of radio button groups dynamically called: wksStud_i
where i = the number of students.
so every student has its own set of 5 radio buttons
lets say we have 3 students on this example.

what i want to do is to check how many of the radio button groups are selected.
so if someone clicks on a radio button it calls a function and checks every element of the groups.

Expand|Select|Wrap|Line Numbers
  1. //studNum = number of students
  2. //register = form name
  3. //name = element name
  4. for (i=1;i<=studNum;i++){
  5.    var name = 'wksStud_'+i;
  6.    for (j=0;j<document.register.name.length;j++){
  7.       if(document.register.name[j].checked==true) {
  8.          rChecked ++;
  9.       }
  10.    }
  11. }
  12. //i want to know how many radio groups have been selected, in other words how many students have a selecting
  13. document.write(rChecked);
  14.  
So i know the problem is that javascript is understanding 'name' to be a element name called 'name' and not my var name that I set.
So i need to let javascript now that i want document.regist er.[my variable name].
How do i do this?
You said Someone else posted a similar question, do you have a link to that post so i can maybe understand it?
Your help is greatly appreciated.
Feb 29 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
So i need to let javascript now that i want document.regist er.[my variable name].
How do i do this?
document.regist er.elements[name]... or document.forms["register"].elements[name].
Feb 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3315
by: Venus | last post by:
Hello, Thanks for your reply. I understand that a control can be created dynamically in several ways: 1) using StringBuilder 2) using Controls.Add 3) using ASP PlaceHolder But this is just for the controls and not for the form itself. What I am trying to achieve is to create an entire form (including controls)
4
2716
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
2
7055
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
26
2817
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when they press next the form generates "How old are you?" 5 times on the page. The customer will answer all 5 questions then press next. Finally, all the local variables get dynamically created and written to a database. I have already taken care of...
0
3399
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10331
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
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
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
7631
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
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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
3001
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.