Current location: Hot Scripts Forums » General Web Coding » JavaScript » copy a part of a dropdown box selection to a textbox


copy a part of a dropdown box selection to a textbox

Reply
  #1 (permalink)  
Old 05-06-07, 07:35 PM
anarchoi anarchoi is offline
Newbie Coder
 
Join Date: Nov 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
copy a part of a dropdown box selection to a textbox

Hi,

I have a form script with a dropdown box listing a lot of albums in this format:
"The Band - Name of the album"

there is another feild the users have to fill, it's a textbox where you have to write the band name. This is just making things harder for my members since the band name is already written in the album name, but filling the textbox is required for the process.

what i would like to do is the following:

When a user either click the submit button, or automaticaly when the dropdown box value is changed:
Automaticaly copy ONLY the text BEFORE the " - " from the dropdown to the textbox


Example:
If user select entry "abcdefg - hijklmnopqrstuvwxyz" from the dropdown, then:
Write "abcdefg" in the textbox



THANKS A LOOOT!
__________________
Reply With Quote
  #2 (permalink)  
Old 05-07-07, 03:23 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
i think you will have to choose a different character than "-", cause some bands have a hyphen in their name. I'd go for the # sign, as i don't know any bands with it in their name (however i non of the bands in your list have a hyphen, you can use that). This will work i think:
Javascript Code:
  1. function displayArtist(){
  2.   var artist_and_album = document.getElementById('dropdown').value;
  3.   var array = artist_and_album.split(/ # /); // here's the # character. replace it with - if you want
  4.   document.getElementById('artist').value = array[0];
  5. }
and this is the html:

HTML Code:
<select id="dropdown" onchange="displayArtist()">
  <option value="Dire Straits # Private Investigations">Dire Straits - Private Investigations</option>
  <option value="The Rolling Stones # Ruby Tuesday">The Rolling Stones - Ruby Tuesday</option>
  <option value="The Beatles # Hey Jude">The Beatles - Hey Jude</option>
</select>

<input type="text" id="artist" /><
Hope this help you out . It's no tested though

cheers
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically populate a text field after making dropdown menu selection sharijl JavaScript 5 03-13-07 07:08 PM
Passing dropdown selection to rest of form sldghmr PHP 3 05-16-06 05:26 AM
Need Help For Multiplt Selection box jaishalg PHP 0 12-22-05 10:49 AM
change drop down box based on textbox talax JavaScript 1 02-24-05 07:38 AM
textbox to text box value Omega2 JavaScript 1 05-28-04 02:02 PM


All times are GMT -5. The time now is 11:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.