| | |
adding Options to Drop Down menu
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2008
Posts: 43
Reputation:
Solved Threads: 0
i need to add an option from list1 to list2 when the user clicks on ADD to List button
but sth is wrong with my code it's not working
function AddItem()
{
var opt = document.getElementById("List1").selectedIndex;
document.getElementById("List2").options.add(opt);
}
can anyone tell me whats wrong ??!!!!!!
but sth is wrong with my code it's not working
function AddItem()
{
var opt = document.getElementById("List1").selectedIndex;
document.getElementById("List2").options.add(opt);
}
can anyone tell me whats wrong ??!!!!!!
The
To move it over you would have to do something more like:
That would move the selected option from List1 to List2.
If you wanted to copy it over, you could use the
document.getElementById("List1").selectedIndex property would not return the actual element, only the position of the selected option in the options array.To move it over you would have to do something more like:
javascript Syntax (Toggle Plain Text)
var firstBox = document.getElementById('List1'); var secondBox = document.getElementById('List2'); var option = firstBox.options[firstBox.selectedIndex]; secondBox.options.add(option);
If you wanted to copy it over, you could use the
cloneNode method. javascript Syntax (Toggle Plain Text)
var firstBox = document.getElementById('List1'); var secondBox = document.getElementById('List2'); var option = firstBox.options[firstBox.selectedIndex]; var newOption = option.cloneNode(true); secondBox.options.add(newOption );
Last edited by Atli; Nov 3rd, 2008 at 7:56 pm.
![]() |
Similar Threads
- XP not booting - lsass.exe not found (Windows NT / 2000 / XP)
- SpeedUp Your Window XP Never Than Before (Windows tips 'n' tweaks)
- Tooltips for drop down boxes (JavaScript / DHTML / AJAX)
- explorer.exe uses 99% CPU (Viruses, Spyware and other Nasties)
- A program with Menus and Loops...HELP!! (Java)
Other Threads in the PHP Forum
- Previous Thread: Is That Possible in PHP
- Next Thread: echo statement in form
Views: 459 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web website xml youtube





