...

View Full Version : javascript writeln problem



Cobata
08-06-2002, 02:56 AM
Hi,

I am having a problem with a javascript.write call.

I have the following inserted in my html:
<SCRIPT LANGUAGE="JavaScript">

<!--

document.writeln('<SELECT NAME="SelectMenu">');

tot = countrylist.length;

for (var i = 1; i <= tot; i++)

document.write("<OPTION>" + countrylist[i]);
document.writeln('</select>');


//-->

</SCRIPT>

with the following in a <script> tag at the top of my page:
var countrylist = new MakeArray("Select an area",
"Belfast",
"Benenden",
"Bethnal Green",
"Bradford",
"Bristol",
"Canary Wharf",
"Cardiff",
"Wolverhmptn");

For some reason it writes in the <select> tags but does not input the <option>'s.
So I end up with a select list with nothing to select.

Can anyone see where I may have gone wrong?

regards

calum

adios
08-06-2002, 03:20 AM
MakeArray() is not a native browser function - it was intended to compensate for the lack of a true Array class constructor function in earlier browsers. You'll need to actually write it in if you mean to use it; unless you're going for full legacy support, skip it and use Array():

<form>
<script type="text/javascript" language="javascript">

var countrylist = new Array("Select an area",
"Belfast",
"Benenden",
"Bethnal Green",
"Bradford",
"Bristol",
"Canary Wharf",
"Cardiff",
"Wolverhmptn");


document.writeln('<SELECT NAME="SelectMenu">');
for (var i=0; i<countrylist.length; i++)
document.writeln('<OPTION>' + countrylist[i] + '</OPTION>');
document.writeln('</SELECT>');

</script>
</form>

Don't forget the option end tags - and the <form> container, for Netscape particularly.

Cobata
08-06-2002, 03:44 AM
thanx for that....works as required now
I didn't even notice that.

cheers

calum



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum