•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,916 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,202 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 730 | Replies: 2
![]() |
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I'm trying to create a tag like routine for music genres. I have an array with various music genres in it. Those genres appear in a select box so they can be added to a text area...
The problem is, I want to be able to add multiple genres instead of a new value replacing the old value.
Heres sample code of what I have so far ...
Is there some subtle thing in "onCLick" I can change to get it to append the value?, ideally comma separated
The problem is, I want to be able to add multiple genres instead of a new value replacing the old value.
Heres sample code of what I have so far ...
php Syntax (Toggle Plain Text)
<?php $tagarray = array ('Classical', 'Pop', 'Blues'); ?> Tags: <select name="tagmenu"> <option value="#">Select Tags</option> <?php foreach($tagarray as &$value){ echo '<option value="'.$value.'">'.$value.'</option>'."\n"; } ?> </select> <input value="Add" type="button" onClick="document.form1.tags.value=document.form1.tagmenu.options[document.form1.tagmenu.selectedIndex].value;"> <br /> <textarea class="small" name="tags" rows="5" cols="40" wrap="virtual"></textarea>
Is there some subtle thing in "onCLick" I can change to get it to append the value?, ideally comma separated
•
•
Join Date: Jul 2008
Posts: 13
Reputation:
Rep Power: 1
Solved Threads: 2
Hi,
You can rephrase your onclick event handling like this.
onClick="document.form1.tags.value +=document.form1.tagmenu.options[document.form1.tagmenu.selectedIndex].value;
Here, I'm assuming that your onclick functionality is working fine
In the above case, the options are added inline to the previous selection. To add options one below another you should add the /n after the += operator. Idea is to save the value of the textarea before changing its value. If want to add comma then you can use the followings
onClick="document.form1.tags.value +=document.form1.tagmenu.options[document.form1.tagmenu.selectedIndex].value + ',';
You can modify this according to your needs so that the "," does not appear un-necessarily.
Another alternative is to provide your users the option of scrollable select with mulitiple select option. In that situation you will not require this button at all! To learn more about scrollable select which permits multiple selection you can refer the following link http://tutorialindia.com/html/html_select_element.php. Here you will need to use both of the select attributes, multiple as well as size.
Hope this helps!
You can rephrase your onclick event handling like this.
onClick="document.form1.tags.value +=document.form1.tagmenu.options[document.form1.tagmenu.selectedIndex].value;
Here, I'm assuming that your onclick functionality is working fine
In the above case, the options are added inline to the previous selection. To add options one below another you should add the /n after the += operator. Idea is to save the value of the textarea before changing its value. If want to add comma then you can use the followingsonClick="document.form1.tags.value +=document.form1.tagmenu.options[document.form1.tagmenu.selectedIndex].value + ',';
You can modify this according to your needs so that the "," does not appear un-necessarily.
Another alternative is to provide your users the option of scrollable select with mulitiple select option. In that situation you will not require this button at all! To learn more about scrollable select which permits multiple selection you can refer the following link http://tutorialindia.com/html/html_select_element.php. Here you will need to use both of the select attributes, multiple as well as size.
Hope this helps!
Last edited by jsrpatna : Jul 16th, 2008 at 9:32 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: drag and drop image across frames
- Next Thread: how to display only checked value in checkbox by using javascript?


Linear Mode