Nov 14, 2001 #1 rhull Programmer May 23, 2001 46 US Is there a way for a select box to allow the user to still type in a value if none of the option will suffice? I dont think there is, but I still want to double check. -Thanks! R
Is there a way for a select box to allow the user to still type in a value if none of the option will suffice? I dont think there is, but I still want to double check. -Thanks! R
Nov 14, 2001 #2 mithrilhall Programmer Jul 27, 2001 635 US You could do it with something like this: <html> <head> <title>test</title> <Script Language="JavaScript"> <!-- function trim(string) { fixedTrim = ""; lastCh = " "; for (x = 0; x < string.length; x++) { ch = string.charAt(x); if ((ch != " " || (lastCh != " ") { fixedTrim += ch; } lastCh = ch; } //alert('Before:' + fixedTrim - 1); if (fixedTrim.charAt(fixedTrim.length - 1) == " " { fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); // alert('After:' + fixedTrim); } if(fixedTrim == '') { //alert('Please enter a color.'); } else { nameditem = fixedTrim; insert(nameditem); //return fixedTrim; } } function insert(nameditem) { if (document.frmTest.txt1.value != '' || ' ') { var newOption = document.createElement("OPTION" newOption.text = nameditem; newOption.value = nameditem; document.frmTest.select1.add(newOption); document.frmTest.txt1.value = ""; document.frmTest.txt1.focus(); } else { alert('Please insert a value.'); } } function colors(selCol) { document.bgColor = selCol; } //--> </Script> </head> <body> <Form name="frmTest"> <input type=text value='' name="txt1"> <input type=button value=insert onclick="JavaScript:trim(txt1.value);document.frmTest.txt1.focus();"> <br> <select name="select1" onChange="colors(this.value);document.frmTest.txt1.focus();" STYLE="WIDTH: 205px;"> <Option><------Choose Here-------></Option> </select> </Form> </body> </html> Upvote 0 Downvote
You could do it with something like this: <html> <head> <title>test</title> <Script Language="JavaScript"> <!-- function trim(string) { fixedTrim = ""; lastCh = " "; for (x = 0; x < string.length; x++) { ch = string.charAt(x); if ((ch != " " || (lastCh != " ") { fixedTrim += ch; } lastCh = ch; } //alert('Before:' + fixedTrim - 1); if (fixedTrim.charAt(fixedTrim.length - 1) == " " { fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); // alert('After:' + fixedTrim); } if(fixedTrim == '') { //alert('Please enter a color.'); } else { nameditem = fixedTrim; insert(nameditem); //return fixedTrim; } } function insert(nameditem) { if (document.frmTest.txt1.value != '' || ' ') { var newOption = document.createElement("OPTION" newOption.text = nameditem; newOption.value = nameditem; document.frmTest.select1.add(newOption); document.frmTest.txt1.value = ""; document.frmTest.txt1.focus(); } else { alert('Please insert a value.'); } } function colors(selCol) { document.bgColor = selCol; } //--> </Script> </head> <body> <Form name="frmTest"> <input type=text value='' name="txt1"> <input type=button value=insert onclick="JavaScript:trim(txt1.value);document.frmTest.txt1.focus();"> <br> <select name="select1" onChange="colors(this.value);document.frmTest.txt1.focus();" STYLE="WIDTH: 205px;"> <Option><------Choose Here-------></Option> </select> </Form> </body> </html>
Nov 14, 2001 Thread starter #3 rhull Programmer May 23, 2001 46 US I should be able to make that work, but I figured it would be a workaround. Thanks! -R Upvote 0 Downvote