473,667 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I pass the element name into a function?

14 New Member
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
4 4434
Dormilich
8,658 Recognized Expert Moderator Expert
use parentForm[btnGroup]
Jul 16 '10 #2
tarek01
14 New Member
Dormilich, I tried that, but it doesn't work.
Jul 16 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
then something’s wrong with your implementation.

EDIT: correction, parentForm = selection.form is wrong
Jul 16 '10 #4
tarek01
14 New Member
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
2955
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 as a string. I want to be able to pass to the function the array name, and the lower and upper limits of the array. But I have no idea how to pass the control name (array name).
4
18917
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" onchange="auto_submit(this.form.name,'Select')"> So, when choosing an option from the select list, the Select button is clicked and the form is submitted. Somehow the function only works when
6
1679
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
2894
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 to the data(e.g. "Maarten Verhage" in XML file). The current situation (problem) is: 1. The XML parser calls the function startElement when it finds a tag,
5
3414
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? /******************************************************** Below is my code: ********************************************************/
2
1379
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 keep hitting a wall trying to get the values. Public Function send(ByVal TheForm As System.Web.UI.HtmlControls.HtmlForm) Dim c As Control For Each c In TheForm.Controls
3
11686
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 BEFORE: strCurrency = oSOAP.eServeSearch(CSTR(Request.Form("T1"))) until the WSDL file changed to have more <element name> T1 is just a field that accepts a STRING
6
5967
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 forms in the database that will use this function, so I need to be able to tell the code which form to unlock. What I have is as follows: Public Function akeyEdit()
6
2717
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
1850
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 function that shows a loading dialog when any AJAX interaction takes place, but I need to cancel it for one particular element and cannot figure out a way without knowing the element name. Here's the code: Ajax.Responders.register({ ...
0
8367
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,...
0
8889
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...
1
8570
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,...
1
6206
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
5677
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
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
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
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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.