473,978 Members | 33,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass formname and select name to function

Hi - I have a dynamically created table, which has a number of forms -
each named consecutively as 'adduserX' where X is a number generated
from ASP.

Within each form, I need to have a button which will call JavaScript,
but pass the name of the form the button is in, as well as a select list
name.

<input name="check" type="button" onclick="mt_sho wHilite(this.ne wname)"
value="submit">

The Javascript function needs to get the options from the select list:

function mt_showHilite(s elname){
var opts=selname.op tions;

...but I keep getting an error 'options' is null or not an object.

I know the problem lies in my onclick text, but can't figure it out.

Can anyone please help?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 6637
Mark <an*******@devd ex.com> writes:
Within each form, I need to have a button which will call JavaScript,
but pass the name of the form the button is in, as well as a select list
name.
What is the select element's name? How do you find it? What is the
structure of the form? Tell us more!
<input name="check" type="button" onclick="mt_sho wHilite(this.ne wname)"
value="submit">
The input element doesn't have a property called "newname". You
pass the value "undefined" to the function.

If you really needed to pass the form *and* select element's names, you
could write
onclick="someFu nction(this.for m.name,this.for m.elements[2].name)"
where "2" is the index of the select element in the form.
(If you know the name when buidling the page, just write that
directly, ofcourse).

More likely, you will want to pass the form and select elements
themselves as arguments. You can always find the name then. I.e.,
drop the "name" from the above.
The Javascript function needs to get the options from the select list:

function mt_showHilite(s elname){
var opts=selname.op tions;
You expect "selname" to be the select element itself, not its name
(the name is a string and doesn't have an "options" property). Good
choice, though, I would stay with it (and change "selname" to "sel").
..but I keep getting an error 'options' is null or not an object.
Because it is undefined.
I know the problem lies in my onclick text, but can't figure it out.


I am not sure you know how to refer to form elements from Javascript.
Show us the form, and we can tell you what to write.

--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lee
Mark said:

Hi - I have a dynamically created table, which has a number of forms -
each named consecutively as 'adduserX' where X is a number generated
from ASP.

Within each form, I need to have a button which will call JavaScript,
but pass the name of the form the button is in, as well as a select list
name.

<input name="check" type="button" onclick="mt_sho wHilite(this.ne wname)"
value="submit" >

The Javascript function needs to get the options from the select list:

function mt_showHilite(s elname){
var opts=selname.op tions;

..but I keep getting an error 'options' is null or not an object.

I know the problem lies in my onclick text, but can't figure it out.


A bigger problem lies in the way you've described the problem.
From your example, it looks to me as if you don't really want
to pass either the form name or the select name to the function.
What you seem to want is a reference to the select object.
We are left to assume that the select object's name is "newname".

The "this" keyword in your onclick handler refers to the button.
The button doesn't have an attribute named "newname", but every
form element does have an attribute named "form", which is a
reference to the form that contains it. If that form contains
an element named "newname", what you want is:

onclick="mt_sho wHilite(this.fo rm.newname)"

Jul 20 '05 #3

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

Similar topics

11
10224
by: charlie_M | last post by:
I have a number of applications where I want to have many onclick='submit()' attached to different 'elements' on a single form ..... which sends the form to a CGI "script" which does all the validation. The problem is.. how can I code the submit()s so the CGI's form collection knows which 'element' was clicked?? I am NOT permitted to use <input type=image...> or any "button" that browsers produce for forms.... the reasons are all client...
2
6481
by: Sean Dockery | last post by:
Which is the following is correct? a) <form ... onSubmit="return checkData()"> b) <form ... onSubmit="return checkData();"> c) <form ... onSubmit="checkData()"> d) <form ... onSubmit="checkData();">
7
2965
by: michael | last post by:
apologies in advance, as not only am i new to learning how to code javascript properly, i'm new to the groups posting thing... i am developing in firefox 1.0+, but will be working in an msie 6.0+ produciton environment ( not my choice, but when is it ever? ). the desired output is that when the end-user selects two radio buttons, one from each 'group', the form / page will open an alert window displaying the values of the radio buttons...
4
5859
by: Paul T. Rong | last post by:
Hello there, I have tried all day but in vain....here is the problem: Form1: there are 50 labels (so far, the number is subject to change), each label caption is a fruit or a vegetable, for example, label1's caption is apple, label2's caption is banana, label3 citron, etc. Form2: one textbox txt0.
0
3340
by: Zlatko Matiæ | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems appear when someone is trying to use it as front-end for real server database systems such as PostgreSQL or MySQL. One of these problems is regarding pass-through queries and parameters. I wanted to have all the code on client, while executing it on...
3
1618
by: Shippy | last post by:
Please help, this is doing my head in!!!! I am sure it is something really simple and ovbious that I am missing but for the life of me I cant find where!!! I have this function... <script> <!-- function update(frm) { var mon, mon1, form;
2
2367
by: ze colmeia | last post by:
Hi all... i'm having trouble trying to pass a field value from a Data Access Page to a Scriptlet. Om my DAP i have: Function returnId() Dim pId pId = formName.Id.value returnId = pId
4
2711
by: JV | last post by:
I thought I once saw somewhere that a global variable, "xyz" for example, could be declared and used so that instead of using "document.formname.elementname.value" one could use "xyz.elementname.value" or use "xyz" in place of "document.formname" anytime a reference to a form element was made. Is this actually true or not? I'm going crazy trying to recall something that might not even exist! Thanks.
1
9390
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then the new page is open in the same popup window as i need to open the new page in the main page window with passing the two textbox parameters into the new page. Program opens the new page but dont know how to pass the two textboxes values into the new page name deceasedToday.asp Needs help in...
0
10174
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
11826
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
11588
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
10919
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
10087
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
8464
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
7618
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
6421
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
6561
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.