User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Sep 2004
Posts: 7
Reputation: mwa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mwa mwa is offline Offline
Newbie Poster

trying to append value to textarea with select box

  #1  
Jul 16th, 2008
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 ...

  1. <?php
  2. $tagarray = array ('Classical', 'Pop', 'Blues');
  3. ?>
  4.  
  5. Tags: <select name="tagmenu">
  6. <option value="#">Select Tags</option>
  7. <?php
  8. foreach($tagarray as &$value){
  9. echo '<option value="'.$value.'">'.$value.'</option>'."\n";
  10. }
  11. ?>
  12. </select>
  13. <input value="Add" type="button" onClick="document.form1.tags.value=document.form1.tagmenu.options[document.form1.tagmenu.selectedIndex].value;">
  14. <br />
  15. <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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Posts: 13
Reputation: jsrpatna is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jsrpatna jsrpatna is offline Offline
Newbie Poster

Re: trying to append value to textarea with select box

  #2  
Jul 16th, 2008
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!
Last edited by jsrpatna : Jul 16th, 2008 at 9:32 am.
Reply With Quote  
Join Date: Sep 2004
Posts: 7
Reputation: mwa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mwa mwa is offline Offline
Newbie Poster

Re: trying to append value to textarea with select box

  #3  
Jul 16th, 2008
Awesome thanks a lot! I figured it was something simple.. I'm just a javascript noob.. I kept trying to append like you do in PHP, with periods.. which of course didn't work.

Thanks again !
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC