Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx for that....works as required now
    I didn't even notice that.

    cheers

    calum


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •