473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How handle embedded blanks in value of <option>

ronverdonk
4,258 Expert 4TB
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:
Nov 16 '06 #1
5 1857
r035198x
13,262 8TB
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]
Nov 17 '06 #2
ronverdonk
4,258 Expert 4TB
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:
Nov 17 '06 #3
r035198x
13,262 8TB
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]
Nov 17 '06 #4
ronverdonk
4,258 Expert 4TB
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:
Nov 17 '06 #5
r035198x
13,262 8TB
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.
Nov 17 '06 #6

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

Similar topics

1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
3
by: Iain Hallam | last post by:
Hi. I've been using display:none on the style property of some <option> elements in my forms, which works fine with Mozilla - as expected it removes the option from my dropdown (although it...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
5
by: bb nicole | last post by:
Below is the list menu of search engine.. How to code if i want to put <option selected>ALL</option> Interface <tr> <td>Job Category:</td> <td><select name="jobCategory"> ...
4
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
7
by: Shrek | last post by:
I have a drop down on a web page and want to change the cursor from default to pointer, so my style definition has style ="cursor: pointer;" the drop down though fails to change from the...
14
by: The Natural Philosopher | last post by:
This is a nasty one and I can't see my way out of it. I have a bunch of select statements in a form, and each select statement has an onchange="do_something(this)" in it, and this works...
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.