Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 6th, 2003, 12:46 PM
Registered User
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old August 6th, 2003, 05:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
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");
Reply With Quote
  #3 (permalink)  
Old August 7th, 2003, 07:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:54 PM.


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