/    Sign up×
Community /Pin to ProfileBookmark

Accessing object: Netscape compatibility

Hi,

I have a weired kind of problem
The script that works in explorer, doesn’t in netscape.

<select name=slot onChange=populateList(this)>
this doesn’t work in netscape, inside populate when display the value, it says null.

I tried this
<select name=slot onChange=populateList(document.forms[0].slot)> bu giving full object access details.

populateList (slot) {
alert (slot.value)
}
This is select, so I don’t know how can I get the VALUE of it.

In I.Explorer – slot.value gives me the value.
In Netscape – it returns null.

Please help

kari

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@MatAug 06.2003 — Have you tried putting the event in quotes?

I always do:

onClick="populateList(this)"

You might also put in the semicolon afterwards, though thats rarely necessary, but it might help.
Copy linkTweet thisAlerts:
@kariauthorAug 06.2003 — Yes I tried that as well.

Inside populateList(slot)

I even tried to access the object like this

alert(window.document.forms[0].slot.value)

It says null value, where as other elements like simple name/value pairs are accesible (<input type=hidden name=xx value=yy> can be accessed.

This is a drop down select.
Copy linkTweet thisAlerts:
@oleragAug 06.2003 — This should work in all browsers w/ JS enabled:

<html>

<head>

<script type="text/javascript">

function showSelected(listObj) {

for (var i=0;i<listObj.length;i++) {

if (listObj.options[i].selected) {

alert("Value: " + listObj.options[i].value);

break;

}

}

}

</script>

</head>

<body>

<center>

<b>Selection Test</b>

<p>

<form>

<select name=selectList1 size="5" onChange="showSelected(this)">

<option value="1">Item #1</option>

<option value="2">Item #2</option>

<option value="3">Item #3</option>

<option value="4">Item #4</option>

<option value="5">Item #5</option>

<option value="6">Item #6</option>

<option value="7">Item #7</option>

</select>

</form>

</center>

</body>

</html>
Copy linkTweet thisAlerts:
@pyroAug 07.2003 — Use the selectedIndex property:

&lt;script type="text/javascript"&gt;
function showSelected(obj) {
alert(obj.options[obj.selectedIndex].value);
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
&lt;p&gt;&lt;select name=selectList1 size="5" onChange="showSelected(this)"&gt;
&lt;option value="1"&gt;Item #1&lt;/option&gt;
&lt;option value="2"&gt;Item #2&lt;/option&gt;
&lt;option value="3"&gt;Item #3&lt;/option&gt;
&lt;option value="4"&gt;Item #4&lt;/option&gt;
&lt;option value="5"&gt;Item #5&lt;/option&gt;
&lt;option value="6"&gt;Item #6&lt;/option&gt;
&lt;option value="7"&gt;Item #7&lt;/option&gt;
&lt;/select&gt;&lt;/p&gt;
&lt;/form&gt;
×

Success!

Help @kari spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...