Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2003, 12:46 PM
Registered User
 
Join Date: Jun 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to higgsy
Default innerHTML problem

Hi,

Im trying to do something in javascript that i would have thought was ridiculously easy, yet i seem to be having problems. Ive basically got a bit of script, an if statement that looks like below

if (something == "this")
{
//code here
}

Where the //code here is i want a bit of script that will populate a dropdown list with three options, which would be something like

<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>

I thought i could do it using innerHTML but doing that has just not worked whatsoever. Does anyone know the code to do this.

Thanks in advance

Regards

Al Higgs
 
Old August 6th, 2003, 05:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

check out the new OPTION syntax, should be in all the books

document.myForm.myDD[1] = new Option("Option Text","OptionValue");
 
Old August 7th, 2003, 07:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

you may also do something like this:

<script language="JavaScript">

var _options = new Array('option 1','option 2','option 3');
document.write ("<select>");
for(i=0;i<_options.length;i++) {
    document.write("<option value=\"" + _options[i] + "\">" + _options[i] + "</option>");
}
document.write("</select>");

</script>

:):D:D:D:D

the genuine genius





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using innerHTML adfranklin BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 0 April 13th, 2007 01:13 AM
Problem with IE's innerHTML and <form> tags??!?! nebulus Javascript 1 February 15th, 2006 05:08 PM
abusing innerHTML ophillip Javascript How-To 3 July 21st, 2005 02:21 AM
Getting InnerHtml ghari Javascript 3 January 3rd, 2005 12:06 PM
innerHTML interrupt Javascript How-To 6 July 22nd, 2004 02:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.