473,395 Members | 1,678 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,395 software developers and data experts.

How can I pass the element name into a function?

14
Hi,

I made a function whereby clicking a radio button will show a hidden radio button sub-group, and when it's unchecked, the radio button sub-group hides again and all the radios in the sub-group are made unchecked.

The problem is I don't know how to pass the 3rd parameter, 'custom' in this example, into the function.

HTML:
Expand|Select|Wrap|Line Numbers
  1. <input type="radio" name="product" value="standard"
  2.    onclick="showSubGroup(this,'customOptions','custom');" />
  3. <input type="radio" name="product" value="custom"
  4.    onclick="showSubGroup(this,'customOptions','custom');" />
  5. <div id="customOptions" style="display:none">
  6.   <input type="radio" name="custom" value="1" />
  7.   <input type="radio" name="custom" value="2" />
  8.   <input type="radio" name="custom" value="3" />
  9. </div>
  10.  
javascript:
Expand|Select|Wrap|Line Numbers
  1. function showSubGroup(selection,showHideItem,btnGroup) {
  2.    var parentForm = selection.form;
  3.    if (selection.value == "custom") {
  4.       document.getElementById(showHideItem).style.display = "block";
  5.    } else {
  6.       for (i=0; i < parentForm.btnGroup.length; i++) {
  7.          parentForm.btnGroup[i].checked = false;
  8.       }
  9.       document.getElementById(showHideItem).style.display = "none";
  10.    }
  11. }
  12.  
If I hardcode the name of the input, it works. For example:
(i=0; i < parentForm.custom.length; i++)
parentForm.custom[i].checked = false

How can I pass the element name so it's variable inside the function?

Thanks in advance.
Jul 16 '10 #1

✓ answered by Dormilich

use parentForm[btnGroup]

4 4426
Dormilich
8,658 Expert Mod 8TB
use parentForm[btnGroup]
Jul 16 '10 #2
tarek01
14
Dormilich, I tried that, but it doesn't work.
Jul 16 '10 #3
Dormilich
8,658 Expert Mod 8TB
then something’s wrong with your implementation.

EDIT: correction, parentForm = selection.form is wrong
Jul 16 '10 #4
tarek01
14
Dormilich, you're right! That works!! I must've clicked too fast before the javascript finished loading. I checked it in FF and IE, and it works perfectly.

I left this code as is:
parentForm = selection.form;


You da man, Dorm!
Jul 16 '10 #5

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

Similar topics

4
by: Stephen Williams | last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere between 5 and 20. What I want to do is write a function that returns the captions of every ticked tick box in an array...
4
by: Sen | last post by:
This is the Javascript function: function auto_submit(form_name, value) { document.form_name.elements.click(); } This is the XHTML: <select name="category"...
6
by: dstefani | last post by:
Hello, I'm trying to pass a var to a function for it to be used as the name of a form element. IE: function doThis(form, elemName) { if( form.elemName.value == false ) {
4
by: Maarten Verhage | last post by:
Hi All, I've made a modified version of the Expat elements.c example. What I want the program to do is to recognize a hardcoded element-name/tag-name and then execute some code which has access...
5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
2
by: Bob Lehmann | last post by:
I have a web form (Form1) that I would like to pass to a function, iterate through it, and retrieve the values of the input elements. I am able to retrieve the element IDs (function below), but...
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
6
by: DMUM via AccessMonster.com | last post by:
Hello I am trying to pass the name of my subform to a function/sub but I can't seem to get it to work. I am using an autokey function (ctrl E) to unlock text boxes on a subform. I have a few...
6
by: adurth | last post by:
Hi! Is there any function that converts a string containing characters that are invalid for use in an element name to a valid one? Thanks, Andreas
1
by: conspireagainst | last post by:
Is there any possible way (I'm using prototype framework) to glean what the name of the container element to be updated (using Ajax.Updater) is? I have appended at the bottom of prototype.js a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.