Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box issue

Status
Not open for further replies.

tmcneil

Technical User
Nov 17, 2000
294
US
Well, I've got some code here that I can see what's happening but don't know how to fix it or if it is a limitation with Firefox vs. IE. I have a drop down on an asp page that has an editable slot. You can type in the value that you want and it stores it into the last slot of of drop-down. However, IE will recognize and store the spaces but FF will not. FF converts the char code into a string and stores it into a variable that stores the word or phrase. The word or phrase gets stored into the index of the drop-down, which removes the space during storage. IE stores the word into the index without any problems. This is the javascript:
Code:
// space bar works in IE, not in FF (char code 32)
	if(c >= 32 && c <= 126)	// Printable characters
	{
	    if ((c == 32) && (navigator.appName=="Netscape")) // if space bar pressed, add an empty space
	        combo_word += " ";  // combo_word stores empty space*/
	    
	    alert("String.fromCharCode(c):" + String.fromCharCode(c) + ";");
	    combo_word += String.fromCharCode(c); // removes spaces
		//element.options[2].value = combo_word;  // take_id will not be selected
		                                          // and default to 0
	                                          
		element.options[2].text = combo_word;
		var combo_wlc = combo_word.toLowerCase();
		var combo_select = 2;
		for(i=1; i<element.options.length; i++)
		{
			combo_sel = element.options[i].text.toLowerCase();
			if(combo_wlc.length <= combo_sel.length)
			{
				combo_sel = combo_sel.substring(0, combo_wlc.length);
				if(combo_wlc == combo_sel)
					combo_select = i;
			}
		}
		element.selectedIndex = combo_select;
	}
	else if((c == 8 || c == 4099) && combo_word.length>0)	// Backspace
	{
		combo_word = combo_word.substring(0, combo_word.length-1);
		//element.options[2].value = combo_word;  // take_id will not be selected
		                                          // and default to 0
		element.options[2].text = combo_word;
		element.selectedIndex = 2;
	}
Is this a limitation and what can I do to fix it? I really need to find a solution for this. Any tips?

Todd
 
Well,

I've incorporated somebody's free code and have been streamlining it for our purposes to get what we need out of it. I noticed the sample on the link below actually works with spaces, but for some reason, with the same code, I cannot get the spaces to work. I'm at the point of looking to try and find someone else's code and use that. It's frustrating and I really don't feel like wasting any more time on this. Here's the link:


T-
 
I tried many things and one space within the text is not a problem, if that is all you need then it will work.

Putting multiple spaces together though, I think can't happen in FF.

Here is the mock-up code I wrote to test this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en">
<head> 
<script type="text/javascript">
function addOption() {
   var addValue = String(document.getElementById("addText").value);
   var selectBox = document.getElementById("thisSelect");
   selectBox.options[selectBox.options.length] = new Option(addValue, addValue, true, true);
   alert(selectBox.options[selectBox.options.length - 1].value);
}    
</script>
</head>
<body>
<div id="wrapper" >
   <select id="thisSelect">
      <option value="hello you">Hello You Dog</option>
   </select>
   <input id="addText" type="text" />
   <input value="ADD" type="button" onclick="addOption()" />
</div>     
</body>
</html>



[monkey][snake] <.
 
monksnake,

I'll have to try the code tonight as I'm working on another project right now.

Thanks,
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top