Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-06-2002, 01:56 AM   PM User | #1
Cobata
New to the CF scene

 
Join Date: Aug 2002
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Cobata is an unknown quantity at this point
javascript writeln problem

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
Cobata is offline   Reply With Quote
Old 08-06-2002, 02:20 AM   PM User | #2
adios
Senior Coder

 
Join Date: Jun 2002
Posts: 1,404
Thanks: 2
Thanked 32 Times in 32 Posts
adios is on a distinguished road
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.
adios is offline   Reply With Quote
Old 08-06-2002, 02:44 AM   PM User | #3
Cobata
New to the CF scene

 
Join Date: Aug 2002
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Cobata is an unknown quantity at this point
thanx for that....works as required now
I didn't even notice that.

cheers

calum
Cobata is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:49 AM.


Advertisement
Log in to turn off these ads.