473,407 Members | 2,326 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,407 software developers and data experts.

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_showHilite(this.newname)"
value="submit">

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

function mt_showHilite(selname){
var opts=selname.options;

...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 6598
Mark <an*******@devdex.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_showHilite(this.newname)"
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="someFunction(this.form.name,this.form.ele ments[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(selname){
var opts=selname.options;
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/rasterTriangleDOM.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_showHilite(this.newname)"
value="submit">

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

function mt_showHilite(selname){
var opts=selname.options;

..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_showHilite(this.form.newname)"

Jul 20 '05 #3

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

Similar topics

11
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...
2
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 ......
7
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+...
4
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...
0
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...
3
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>...
2
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
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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,...

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.