By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Need Help With Passed Variables in <SELECT>

P: n/a
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.value 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='displayTrain(train.options.value)'>");
for (i=0;i<Trains.length;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+fillSpaces[22-trainName.length]+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
Share this Question
Share on Google+
3 Replies


P: n/a
In article <21*************************@dcsi.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.value 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='displayTrain(train.options.value)'>");
for (i=0;i<Trains.length;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+fillSpaces[22-trainName.length]+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='displayTrain(document.selectIt.train.opt ions[document.selectIt.
train.selectedIndex].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

P: n/a
@SM


"Dennis M. Marks" a *crit :

In article <21*************************@dcsi.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.value 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='displayTrain(train.options.value)'>");
for (i=0;i<Trains.length;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+fillSpaces[22-trainName.length]+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='displayTrain(document.selectIt.train.opt ions[document.selectIt.
train.selectedIndex].value)'>");


much better again with :

onChange='displayTrain(document.selectIt.train.opt ions[document.selectIt.
train.options.selectedIndex].value)'>");
Jul 20 '05 #3

P: n/a
"@SM" <st**************@wanadoo.fr> wrote in message
news:3F***************@wanadoo.fr...
<snip>
document.write("<SELECT size='8' NAME='train'
onChange='displayTrain(document.selectIt.train.o ptions[
document.selectIt.train.selectedIndex].value)'>");


much better again with :

onChange='displayTrain(document.selectIt.train.op tions[
document.selectIt.train.options.selectedIndex].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="dispalyTrain(this.options[this.selectedIndex].value);"

-would be optimal for cross-browser scripting.

Richard.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.