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

Control name as Script parameter

Hi All,

My next little hurdle is how to pass a controls name to a function to access
the control inside the function:

Say I have the followind function:

function jblf_use(nId, cName) {
doc = this.opener.document;
doc.TASK_FORM_Form.Customer_ID.value = nId;
doc.TASK_FORM_Form.Customer_ID_SLE.value = cName;
}

To make it more generic, I would need to pass the name of the control, in
this case "Customer_ID" as a parameter and somehow make use of it, but this
is where I am stuck. The syntax. I have books, but can't seem to find
anything...

function jblf_use(nId, cName, cControl) { // cControl
=="Customer_ID"
doc = this.opener.document;
doc.TASK_FORM_Form.Customer_ID.value = nId;
doc.TASK_FORM_Form.Customer_ID_SLE.value = cName;
}
TIA,

Tom

Jul 23 '05 #1
3 3958
Tom Szabo wrote:
Hi All,

My next little hurdle is how to pass a controls name to a function to access
the control inside the function:


Presuming that TASK_FORM_Form is the name of a form:

function jblf_use(nId, cName, cControl) { // cControl =="Customer_ID"
doc = this.opener.document;
doc.TASK_FORM_Form.cControl.value = nId;
doc.TASK_FORM_Form.cControl+'_SLE'.value = cName;
}

You could also try:

doc.TASK_FORM_Form.elements[cControl].value = nId;
doc.TASK_FORM_Form.elements[cControl+'_SLE'].value = cName;

There are a few other options that may be available depending upon
how you are calling the function.

Rob.
Jul 23 '05 #2
On Sun, 14 Nov 2004 18:34:35 +1000, RobG <rg***@iinet.net.auau> wrote:

[snip]
doc.TASK_FORM_Form.cControl.value = nId;
doc.TASK_FORM_Form.cControl+'_SLE'.value = cName;
That wouldn't work at all.

The second line would be treated as: "Assign nId to the value property of
the cControl element within the form, TASK_FORM_Form." That is, cControl
would be treated literally.

The third line would be: "First, assign the value of cName to the value
property of the string, '_SLE'. Second, obtain a reference to the cControl
element in the form, TASK_FORM_Form. Finally, concatenate the results of
steps 1 and 2."

[snip]
doc.TASK_FORM_Form.elements[cControl].value = nId;
doc.TASK_FORM_Form.elements[cControl+'_SLE'].value = cName;


Much better. :)

To the OP: An article in the FAQ notes give thorough treatment to
accessing form controls. See
<URL:http://www.jibbering.com/faq/faq_notes/form_access.html>.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3


"RobG" <rg***@iinet.net.auau> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Tom Szabo wrote:
Hi All,

My next little hurdle is how to pass a controls name to a function to access the control inside the function:


Presuming that TASK_FORM_Form is the name of a form:

function jblf_use(nId, cName, cControl) { // cControl =="Customer_ID"
doc = this.opener.document;
doc.TASK_FORM_Form.cControl.value = nId;
doc.TASK_FORM_Form.cControl+'_SLE'.value = cName;
}

You could also try:

doc.TASK_FORM_Form.elements[cControl].value = nId;
doc.TASK_FORM_Form.elements[cControl+'_SLE'].value = cName;

There are a few other options that may be available depending upon
how you are calling the function.

Rob.


Thanks Rob,

great, this is what I needed :-))))

Tom
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
4
by: Remi Hugnon | last post by:
Hi, I want to build an expandable treeview. I saw some code on VB but I know only C# I plan for my class that each nodes has its own id (using span for example). Into a single aspx page...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
0
by: nate | last post by:
the error returned is this: Server Error in '/AnnAccRpt' Application. -------------------------------------------------------------------------------- Could not find control 'DropDownList1' in...
1
by: Bill_W_Stephens | last post by:
I have a complicated page with several submit buttons. I don't want to create multiple forms because much of the input is shared and the code is getting very ugly. However I would like to determine...
4
by: Sevu | last post by:
I am working with ASP.NET.I am using ReportViwer Control to show my report.I like to add dropdownlist with in the reportviewer control. ( Not top to the control some thing like that).I need to...
0
by: amily | last post by:
hi, I am a beginner in asp.net. I am designing a page using details view control in asp.net using VB. The page is about inserting information and then sending it to the database. I want that the...
2
by: Danielle | last post by:
Hello all - Thank you in advance for any help you are able to provide. I am populating a gridview from a stored procuedure. The returned data is a name, phone number, email and guid of a...
0
by: John Mason | last post by:
Hi, I've been trying for most of the day to get a FormView control to work. I would like to display a single record, based on a unique user id (loginid), which I am retreiving from a cookie. No...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.