473,569 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help With Passed Variables in <SELECT>

I have a problem with the following code. It generates a
<FORM><SELECT>< OPTION> list. There is no problem in the generating. The
problem is in the execution as follows.

It works fine in Mac IE with and without the <FORM></FORM>.

In Mac Netscape 6 the onChange does not activate if there is no
<FORM></FORM>. When I put it in a form as indicated below the value of
train.options.v alue is undefined. What am I doing wrong?

As I said there is no problem in IE and mayby other browsers. It may be
just a Mac Netscape 6 problem.
<!--
document.write( "<FORM name='selectIt' action='post'>" );
document.write( "<SELECT size='8' NAME='train'
onChange='displ ayTrain(train.o ptions.value)'> ");
for (i=0;i<Trains.l ength;i++) {
if (Trains[i][3][0]=="NA") document.write( "<OPTION value="+i+"
class='na'>");
if (Trains[i][3][0]=="DD") document.write( "<OPTION value="+i+"
class='dd'>");
if (Trains[i][3][0]!="NA" && Trains[i][3][0]!="DD")
document.write( "<OPTION value="+i+" class='aa'>");
var trainName = Trains[i][0];
document.write( trainName+fillS paces[22-trainName.lengt h]+searchStation( T
rains[i][2][0])+" /
"+searchStation (Trains[i][2][Trains[i][2].length-1]));
document.write( "<\/OPTION>");
};
document.write( "<\/SELECT>");
document.write( "\/FORM>");
//-->

The page is http://www.dcs-chico.com/~denmarks/amtrak.html (without the
<FORM></FORM> wrapper).

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #1
3 1576
In article <21************ *************@d csi.net>, Dennis M. Marks
<de******@dcsi. net> wrote:
I have a problem with the following code. It generates a
<FORM><SELECT>< OPTION> list. There is no problem in the generating. The
problem is in the execution as follows.

It works fine in Mac IE with and without the <FORM></FORM>.

In Mac Netscape 6 the onChange does not activate if there is no
<FORM></FORM>. When I put it in a form as indicated below the value of
train.options.v alue is undefined. What am I doing wrong?

As I said there is no problem in IE and mayby other browsers. It may be
just a Mac Netscape 6 problem.
<!--
document.write( "<FORM name='selectIt' action='post'>" );
document.write( "<SELECT size='8' NAME='train'
onChange='displ ayTrain(train.o ptions.value)'> ");
for (i=0;i<Trains.l ength;i++) {
if (Trains[i][3][0]=="NA") document.write( "<OPTION value="+i+"
class='na'>");
if (Trains[i][3][0]=="DD") document.write( "<OPTION value="+i+"
class='dd'>");
if (Trains[i][3][0]!="NA" && Trains[i][3][0]!="DD")
document.write( "<OPTION value="+i+" class='aa'>");
var trainName = Trains[i][0];
document.write( trainName+fillS paces[22-trainName.lengt h]+searchStation( T
rains[i][2][0])+" /
"+searchStation (Trains[i][2][Trains[i][2].length-1]));
document.write( "<\/OPTION>");
};
document.write( "<\/SELECT>");
document.write( "\/FORM>");
//-->

The page is http://www.dcs-chico.com/~denmarks/amtrak.html (without the
<FORM></FORM> wrapper).


I changed the SELECT line as follows:

document.write( "<SELECT size='8' NAME='train'
onChange='displ ayTrain(documen t.selectIt.trai n.options[document.select It.
train.selectedI ndex].value)'>");

The fully qualified variable name solved the problem.

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #2
@SM


"Dennis M. Marks" a *crit :

In article <21************ *************@d csi.net>, Dennis M. Marks
<de******@dcsi. net> wrote:
I have a problem with the following code. It generates a
<FORM><SELECT>< OPTION> list. There is no problem in the generating. The
problem is in the execution as follows.

It works fine in Mac IE with and without the <FORM></FORM>.

In Mac Netscape 6 the onChange does not activate if there is no
<FORM></FORM>. When I put it in a form as indicated below the value of
train.options.v alue is undefined. What am I doing wrong?

As I said there is no problem in IE and mayby other browsers. It may be
just a Mac Netscape 6 problem.
<!--
document.write( "<FORM name='selectIt' action='post'>" );
document.write( "<SELECT size='8' NAME='train'
onChange='displ ayTrain(train.o ptions.value)'> ");
for (i=0;i<Trains.l ength;i++) {
if (Trains[i][3][0]=="NA") document.write( "<OPTION value="+i+"
class='na'>");
if (Trains[i][3][0]=="DD") document.write( "<OPTION value="+i+"
class='dd'>");
if (Trains[i][3][0]!="NA" && Trains[i][3][0]!="DD")
document.write( "<OPTION value="+i+" class='aa'>");
var trainName = Trains[i][0];
document.write( trainName+fillS paces[22-trainName.lengt h]+searchStation( T
rains[i][2][0])+" /
"+searchStation (Trains[i][2][Trains[i][2].length-1]));
document.write( "<\/OPTION>");
};
document.write( "<\/SELECT>");
document.write( "\/FORM>"); wold be :
document.write( "<\/FORM>"); //-->

The page is http://www.dcs-chico.com/~denmarks/amtrak.html (without the
<FORM></FORM> wrapper).


I changed the SELECT line as follows:

document.write( "<SELECT size='8' NAME='train'
onChange='displ ayTrain(documen t.selectIt.trai n.options[document.select It.
train.selectedI ndex].value)'>");


much better again with :

onChange='displ ayTrain(documen t.selectIt.trai n.options[document.select It.
train.options.s electedIndex].value)'>");
Jul 20 '05 #3
"@SM" <st************ **@wanadoo.fr> wrote in message
news:3F******** *******@wanadoo .fr...
<snip>
document.writ e("<SELECT size='8' NAME='train'
onChange='dis playTrain(docum ent.selectIt.tr ain.options[
document.sele ctIt.train.sele ctedIndex].value)'>");


much better again with :

onChange='disp layTrain(docume nt.selectIt.tra in.options[
document.selec tIt.train.optio ns.selectedInde x].value)'>");


Not really better because the selectedIndex property belongs to the
SELECT element and not the options collection. In practice it will work
with some SELECT element implementations because they make the options
property a reference to themselves and then provide the options as
numerically indexed properties of themselves. But for cross-browser
scripting (and W3C HTML DOM compliance) it would be better to access the
selectedIndex property as a property of the SELECT element.

However, the reference to the select element named "train" via the
document (or better the document.forms collection) is not necessary in
the onchange event handling code as that code is used by the browser to
create a function object that is assigned to the SELECT element's
onchange property and invoked as a method of the SELECT element in
response to a change event. In any JavaScript function executed as a
method of an object the - this - keyword is a reference to that object,
so in the event handling function of the SELECT element the - this -
keyword is a reliable reference to that element.

onchange="dispa lyTrain(this.op tions[this.selectedIn dex].value);"

-would be optimal for cross-browser scripting.

Richard.
Jul 20 '05 #4

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

Similar topics

2
3811
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of available articles ("availableItems") and a list of articles already in an issue ("selectedItems"). What I want is to be able to move articles...
3
3097
by: K. Lobe | last post by:
list box based on a POST method to the same page. frm.cmbList.Value=Request.Form("cmbList") doesn't work. When the page loads, it reloads the <SELECT>, so not sure how to get the list to go to the item. Any ideas? many thnx,
1
2384
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php method=post > <select name= "name">
4
11254
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting at the top of the list moving down towards the bottom. The problem I was having was that the <select> control was scrolling back to the top of the...
4
6106
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on Firefox, Safari and Konqueror, but the onchange event just doesn't fire on IE6. Firefox's javascript console shows no errors, and the IE script...
5
8297
by: Brian Foley | last post by:
Hello, I am used to using the label tag with check boxes and radio buttons in html forms. This allows me to click on the text of the label to activate/deactivate the check box / button, rather than having to click on the (possibly small) box or button. I recently tried to assign a label to a select "drop down list", but found that when...
6
19591
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works fine in Internet Explorer, however in Firefox the dropdown only displays the first option in the list, and when clicked the other values aren't...
4
39327
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
7
6536
by: Shrek | last post by:
I have a drop down on a web page and want to change the cursor from default to pointer, so my style definition has style ="cursor: pointer;" the drop down though fails to change from the default curor. I've tryed applying the style to the <select> tag and to the <option> tags to no avail.
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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...
0
7924
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. ...
0
7970
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...
0
6284
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...
1
5513
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...
0
3653
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...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.