Connecting Tech Pros Worldwide Help | Site Map

How handle embedded blanks in value of <option>

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#1: Nov 16 '06
I don't know much of JavaScript, hence this question.
I have an select list with an option entry[html]<option value="This is a value"><This is a value</option>[/html]
When I try to handle the option value, when it is selected, in JavaScript I use command[html]selValue = sel.options[sel.selectedIndex].value;[/html] the variable selValue only contains the string 'This'. It obviously cuts off the value at the point where it encounters a blank character.

I could circumvent this problem by encoding it before storing it in the <option> statement and decoding it after assigning it to selVal.
But is there not another way of capturing the complete value string in JS without this bypass?

Thanks very much for any help or hint you can give me.

Ronald :cool:
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Nov 17 '06

re: How handle embedded blanks in value of <option>


Quote:

Originally Posted by ronverdonk

I don't know much of JavaScript, hence this question.
I have an select list with an option entry[html]<option value="This is a value"><This is a value</option>[/html]
When I try to handle the option value, when it is selected, in JavaScript I use command[html]selValue = sel.options[sel.selectedIndex].value;[/html] the variable selValue only contains the string 'This'. It obviously cuts off the value at the point where it encounters a blank character.

I could circumvent this problem by encoding it before storing it in the <option> statement and decoding it after assigning it to selVal.
But is there not another way of capturing the complete value string in JS without this bypass?

Thanks very much for any help or hint you can give me.

Ronald :cool:

Did you try it without the extra <
ie
this
[HTML] <option value="This is a value">This is a value</option>[/HTML]
[color=#000080]as oppoosed to[/color]

[HTML] <option value="This is a value"><This is a value</option>[/HTML]
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#3: Nov 17 '06

re: How handle embedded blanks in value of <option>


Quote:

Originally Posted by r035198x

Did you try it without the extra <
ie
this

[HTML] <option value="This is a value">This is a value</option>[/HTML]
[color=#000080]as oppoosed to[/color]

[HTML] <option value="This is a value"><This is a value</option>[/HTML]

Sorry that sample was a typo at my side. The statement I use is[html]<option value="This is a value">This is a value</option>[/html]
Ronald :cool:
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Nov 17 '06

re: How handle embedded blanks in value of <option>


Quote:

Originally Posted by ronverdonk

Sorry that sample was a typo at my side. The statement I use is[html]<option value="This is a value">This is a value</option>[/html]
Ronald :cool:

I've just tried this and it worked perfectly

[HTML]
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Temp</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type = "text/css">
body { background-color: #ddd }
</style>
<script language = "JavaScript" type="text/javascript">
function test() {
sel = document.myForm.box;
selValue = sel.options[sel.selectedIndex].value;
alert(selValue);
}
</script>
</head>
<body>
<h1> Temp</h1>
<form name = "myForm" id="myForm" action="">
<tr>
<td><select name ="box"><option value="This is a value">This is a value</option></select></td>
</tr>
<tr>
<td>
<input name = "show" type = "button" value = "show"
onclick = "test()" /></td>
</tr>
</table>
</form>
</body>
</html
[/HTML]
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#5: Nov 17 '06

re: How handle embedded blanks in value of <option>


Thans very much. The fault was entirely mine. I that particular entry I forgot to enclose the qoutes around the value and that caused it.

Again sorry for any confusion I may have caused.

Ronald :cool:
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Nov 17 '06

re: How handle embedded blanks in value of <option>


Quote:

Originally Posted by ronverdonk

Thans very much. The fault was entirely mine. I that particular entry I forgot to enclose the qoutes around the value and that caused it.

Again sorry for any confusion I may have caused.

Ronald :cool:

Happens to everyone that.
And congtats for turning 800.
Reply