Javascript + space between string
HI,
I have a drop box on my jsp page, I am selecting multiple values and passing them to serlvet.Onclcick event of my button I am callin JS function, and I am seperating selected values by comma in a string.
But if string contains space inbetween it takes only first half of (string before space)
For example, if selected names are 'AAA BBB', 'ABC', 'CCC'
It takes: AAA,ABC,CCC
it doesn't take anything after space.
Could anyone please help with sample code, I will really appreciate it?
Thanks
[551 byte] By [
ASH_2007a] at [2007-11-27 8:03:38]

# 1
Like I mentioned in the other topic, it's probably because your value isn't between double quotes.
In the code I've given below, you'll get alerts saying 'First Value', 'Second' and 'Third Value'. For the second one, the 'Value' word is missing since it isn't enclosed in double quotes.
<html>
<script>
function getDropDownValues( )
{
dropDownBox = document.getElementById('dropdownexample');
for ( i = 0; i < dropDownBox.options.length; i++ )
alert(dropDownBox.options[i].value);
}
</script>
<body>
<select id="dropdownexample">
<option value="First Value">1</option>
<option value=Second Value>2</option>
<option value="Third Value">3</option>
</select>
<input type="button" value="Show Me The Values" onclick="getDropDownValues();" />
</body>
</html>
Oh, and JavaScript doesn't have anything to do with Java. And these are Java forums :)
# 2
Oh, and JavaScript doesn't have anything to do
> with Java. And these are Java forums :)
__Lol..sorry
But It's in double quotes, I am populating them from Database. Here is the Code:<TD><SELECT id="CUSTOMER_NAME" NAME="DROPBOX" MULTIPLE>
<OPTION VALUE='null' >None
<%for(int i = 0; i < al.size(); i++)
out.println("<OPTION VALUE= "+ al.get(i).toString().trim() + ">" + al.get(i).toString().toUpperCase().trim());
%>
</OPTION>
</SELECT></TD>
# 3
There is no double quotes in that HTML-code in your for-loop.
Your code would render:
<TD><SELECT id="CUSTOMER_NAME" NAME="DROPBOX" MULTIPLE>
<OPTION VALUE='null' >None
<OPTION VALUE= Foo Bar>FOO BAR
</OPTION>
</SELECT></TD>
And you should substitute your single quote (') with double (") in the above HTML-code.
# 4
> out.println("<OPTION VALUE= "+
> + al.get(i).toString().trim() + ">" +
> al.get(i).toString().toUpperCase().trim());
>
> %>
> </OPTION>
> </SELECT></TD>[/code]
But it isn't in double quotes! This is exaclty what I meant. It's in double quotes for the Java string! But not for the HTML code!
It should be like this
out.println("<OPTION VALUE= \""+ al.get(i).toString().trim() + "\">" + al.get(i).toString().toUpperCase().trim()); //need to escape the double quotes
You should check the HTML you generate by clicking 'View Source' in your browser.
Also, like mentioned above, the 'null' is wrong. You're mixing you Java and HTML. You should just print an empty string "" there or something similar.