By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Values from drop down box

P: 31
Hi

I am trying to get the following code to work I believe it should work but i don't understand why it doesn't :(

I am trying to get it to take words that have been placed into the accepted dropdown box, and place a semi-colon at the end of each word, so that I have a delimited list of words.

Which I then wish to pass into to the URL, which would allow me to do the necessary processing on the words in my PHP scripts


my code looks like the following

Expand|Select|Wrap|Line Numbers
  1. function createLinks()
  2. {
  3.   var Values = '';
  4.     var selectBox = document.getElementById('acceptwords').options;
  5.     for(var i=0; i<selectBox.length; i++) { // Loop through the options.
  6.       Values += selectBox[i].value + ";"; // Concatenate the option values into the Value string.
  7.     }
  8.     Values=Values.replace(/;$/,""); // Trim the leading semi-colon.
  9.   window.location="http://www.asite.com?words="+Values;  
  10. }
  11.  
and i call it using the

[HTML]
<input type="button" value="Make Link" onClick="createLinks()">
[/HTML]

any help would be greatly appreciated

Boyindie
Jan 21 '08 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
It should work. Show the code for the select element.
Jan 21 '08 #2

P: 31
It should work. Show the code for the select element.
What do you mean by the select element?

The actual drop down box

sorry i am new to javascript
Jan 21 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Yes, the drop down box.
Jan 21 '08 #4

P: 31
the dropdown box looks like the following

[HTML]<table border="0">
<tr>
<td>
<select id="wordlist" name="sel1" size="10" multiple="multiple">
<option value="">Word List</option>
</select>
</td>
<image src=""
onClick="moveOptions1();"/><br /><br />
<image src="h"
onClick="moveOptions2();"/>
</td>
<td>

</select>
<input type="button" value="Make Link" onClick="createLinks()">

</td>
</tr>
</table>[/HTML]
Jan 21 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Where's the drop down box with id "acceptwords"?
Jan 21 '08 #6

P: 31
Where's the drop down box with id "acceptwords"?
Appologies

I must of messed up the paste somehow

this is my drop down box

[HTML]<table border="0">
<tr>
<td>
<select id="wordlist" name="sel1" size="10" multiple="multiple">
</select>
</td>
<td align="center" valign="middle">
<image src="http://right_arrow.png"
onClick="moveOptions1();"/><br />
<image src="http:///left_arrow.png"
onClick="moveOptions2();"/>
</td>

<td>
<select id="acceptWords" name="sel2" size="10" multiple="multiple">
</select>
<input type="button" value="Create Links" onClick="createLinks();">
</td>
</tr>
</table>[/HTML]
Jan 21 '08 #7

acoder
Expert Mod 15k+
P: 16,027
JavaScript is case-sensitive. The element has an id of "acceptWords" and you're looking for "acceptwords".
Jan 21 '08 #8

P: 31
thats it working thank you

i can't believe i haven't noticed that after almost two days!
Jan 21 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Just a capital W, it was. Glad you got it working.
Jan 21 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.