/    Sign up×
Community /Pin to ProfileBookmark

Explain to me please.

I have the following snippet of code that works without errors in FF and IE.

The display looks and acts correctly and as expected with FF.

However, in IE the first selection list does NOT display the ” (blank) entry whereas the hard coded version below it on the page does display the blank entry.

Why??? What is the difference between FF and IE for this script.

It appears that IE does not recognize the blank option unless hard coded. In fact it even changes the index values of the lists even when they are the same as seen by the alert test message.

Is there a work-around that functions the same in both browsers or is it just necessary that I hard code the select list values to avoid the missing (blank) option that I want to give the user?

[code=php]
<html>
<head>
<title>Test</title>
<script type=”text/javascript”>
var ReasonsList = new Array (
“”, “Out”, “Holiday”, “Business”, “Vacation”, “Personal”, “Midterms”, “Finals”
)

function SelectListReasons() {
document.write(‘<select id=”SLReason” name=”SLReason”‘);
for (var i=0; i<ReasonsList.length; i++) {
document.write(‘<option value=”‘+ReasonsList[i]+'” />’+ReasonsList[i]);
}
document.write(‘</select>’);
}
function xferSelectedValue() {
var sel = document.getElementById(‘SLReason’);
var sndx = sel.selectedIndex;
var sval = sel.options[sndx].value;
alert(sndx+’:’+sval); // for testing only
document.getElementById(‘selectlistvalue’).value = sndx+’:’+sval;
}
</script>
</head>
<body>
<h1>Test of Select</h1>
<script type=”text/javascript”>SelectListReasons();</script>
<input type=”text” id=”selectlistvalue” value=””> Chosen value
<br />
<button onclick=”xferSelectedValue()”>Get Selected Value</button>

<p />
<select id=”SList” name=”SList”>
<option value=””>
<option value=”Out”>Out
<option value=”Holiday”>Holiday
<option value=”Business”>Business
<option value=”Vacation”>Vacation
<option value=”Personal”>Personal
<option value=”Midterms”>Midterms
<option value=”Finals”>Finals
</select>
</body>
</html>
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERauthorSep 09.2006 — It's been several days since I first posted this.

Perhaps someone new is looking now?

Bottom line, I would like the IE select box show a blank entry just like the FF version.
Copy linkTweet thisAlerts:
@Arty_EffemSep 09.2006 — It's been several days since I first posted this.

Perhaps someone new is looking now?

Bottom line, I would like the IE select box show a blank entry just like the FF version.[/QUOTE]
Typo:
[CODE] document.write('<select id="SLReason" name="SLReason"');[/CODE]Missing '>'
Copy linkTweet thisAlerts:
@pros940Sep 10.2006 — Thank you Arty for replying with the answer. I am new to JavaScript and spent a few hours trying to google an answer for JMRKER's post to no avail. For those like me who are beginners, the missing '>' in the above code goes after SLReason"

document.write('<select id="SLReason"> name="SLReason"');
Copy linkTweet thisAlerts:
@JMRKERauthorSep 10.2006 — Thank you so much 'Arty Effem'. I've been searching for that for 2 days.

The program would not give me an error, but still didn't work as I expected.

Was bugging the fool out of me.

for pros940:

document.write('<select id="SLReason" name="SLReason"');

should be:

document.write('<select id="SLReason" name="SLReason">');
Copy linkTweet thisAlerts:
@pros940Sep 10.2006 — Thanks JMRKER for correcting me. It worked the other way too when I added it. Nice guess on my part. I have much to learn.
Copy linkTweet thisAlerts:
@JMRKERauthorSep 10.2006 — pros940:

It probably worked the first way you tried it because HTML is somewhat forgiving with errors. It would have failed miserably with XML because of the unmatched tags.

Errors in javascript, I've found, are somewhat in the middle, but very sticky with syntax and case of the letters.
×

Success!

Help @JMRKER 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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