Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 September 24th, 2004, 07:35 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default advanced listobox! Please Help

Hello Guyz...

I`d like to have a listbox with the follow values.
- English
- French
- German
- Other...

But when the user will select "Other..." I`d like to give him the option to write his own value in that listbox/textbox.
I`m quite new to JavaScript. So I`d be thankful if someone could give me the script to do that!

Thank you in advance!
 
Old September 24th, 2004, 01:27 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I suggest doing something like this:

<form id='form1' [other attributes]>
<select name='lang' onchange='checkIfOther(this.options[this.selectedIndex].value,this)'>
<option value='english'>english</option>
<option value='french'>french</option>
<option value='german'>german</option>
<option value='add'>add...</option>
</select>
<input type='submit' value='go'/>
</form>
<script type='text/javascript'>
function checkIfOther(lang,sel)
{
    if(lang=="add") {
    language = prompt('enter your language:','');
    if(language!==false)
    {
        sel.options.length++;
        sel.options[sel.options.length].value=language;
        sel.options[sel.options.length].text=language;
    }
}
}
</script>

HTH!

-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
 
Old September 27th, 2004, 01:19 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It`s quite good. Thank you for your reply!

But it`s not working fine... because when the user insert`s a language on the menu the value in the listbox is invisible.
 
Old September 28th, 2004, 03:30 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

What exactly do you mean? It just disappears? Sounds like IE to me :-)

-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
 
Old September 29th, 2004, 01:49 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok... probably is IE fault or... I don`t know what`s wrong! Thank you for your reply! ;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this forum too advanced for me? Randy Visual Basic 2008 Essentials 9 June 11th, 2008 08:49 PM
Where are the Advanced button? micror BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 August 7th, 2006 07:28 AM
Looking for advanced CSS dimo414 BOOK: Professional CSS: Cascading Style Sheets for Web Design 0 May 29th, 2006 10:57 PM
Advanced bitmap help UsrNm C++ Programming 1 September 13th, 2004 09:49 AM
advanced search Moharo Pro PHP 1 February 2nd, 2004 04:43 PM





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