Forum Moderators: open

Message Too Old, No Replies

problem:how put "input" on "select"£¿

HTML&Javascript question

         

waxbird

5:40 am on Feb 2, 2004 (gmt 0)

10+ Year Member



run my code,you will find "select" on "input",the problem is:how can i put "input" on "select"?
this is my code:
================================================
<table border=1>
<tr>
<td>TEST</td>
<td nowrap>
<select name=aaa style="width:200">
<input name=bbb style="width:50;margin-left:-20">
</td>
</tr>
</table>

Purple Martin

6:10 am on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't think so.

What are you trying to achieve with this? There may be another approach.

Krapulator

6:27 am on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why on earth would you want to do that?

DrDoc

6:36 am on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can see what you're trying to do, and quite honestly -- it's very understandable that you would want to do something like that. However, it's not possible to get an editable select box. If you wouldn't mind expanding on what exactly you're trying to accomplish, maybe we can help you find a suitable solution.

waxbird

6:56 am on Feb 2, 2004 (gmt 0)

10+ Year Member



DrDoc,you are great.
before this,i made some code to get editable select,but it is too fussy.
that code below:
===================================================
<script>
function pp(){
se.options[2]=new Option(ok=(se.options[2])?se.options[2].innerText+String.fromCharCode(event.keyCode):String.fromCharCode(event.keyCode),"client")
se.selectedIndex=2;
}

function edit(){
if(se.options[2]){
if(event.keyCode==8){
var str=se.options[2].innerText;
var len=str.length;
se.options[2].innerText=str.substring(0,len-1);
if(se.options[2].innerText=="")se.remove(2);
}
if(event.keyCode==13)return false;
if(event.keyCode==32){
se.options[2].innerText+=" ";

}
}
}
</script>
<select id=se onkeypress=pp() onkeyup="edit()">
<option>TEST
<option>javascript
</select>

YOU CAN INPUT LETTER
</td></tr>
</table></center>
<br>
<br>

waxbird

7:00 am on Feb 2, 2004 (gmt 0)

10+ Year Member



Now,i want find a way to let "input" on "select",
can we do it?

DrDoc

4:25 pm on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sort of... You cannot make the select itself editable... But you can do something similar. Consider the following code:


<html>
<head>
<script type="text/javascript">
function listSearch(which) {
fontSearch = which.field.value;
if(event.keyCode==40 ¦¦ event.keyCode==34) {
// 40 = Pressed down key
// 34 = Pressed pgdn key
selNow = which.list.selectedIndex;
selMax = which.list.length - 1;
if(selNow!=0 && fontSearch!=which.list.options[selNow].value) {
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
else {
if(event.keyCode==40) {
which.list.selectedIndex = (selNow==selMax?selMax:selNow+1);
}
else if(event.keyCode==34) {
which.list.selectedIndex = (selNow>(selMax-10)?selMax:selNow+10);
}
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
}
else if(event.keyCode==38 ¦¦ event.keyCode==33) {
// 38 = Pressed up key
// 33 = Pressed pgup key
selNow = which.list.selectedIndex;
if(selNow!=0 && fontSearch!=which.list.options[selNow].value) {
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
else {
if(event.keyCode==38) {
which.list.selectedIndex = (selNow<2?1:selNow-1);
}
else if(event.keyCode=33) {
which.list.selectedIndex = (selNow<11?1:selNow-10);
}
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
}
else if(fontSearch!="") {
regexp = new RegExp("^" + fontSearch, "i");
found = 0;
for(i=1; i<which.list.length; i++) {
listFont = which.list.options[i].value;
if(listFont.match(regexp)) {
found = i;
i = which.list.length;
}
}
which.list.selectedIndex = found;
}
else {
window.status=event.keyCode;
}
}
</script>
<style type="text/css">
body {
font: 10px Verdana;
}
form {
margin: 0;
}
fieldset {
border: 1px solid #999;
padding: 10px;
width: 500px;
}
legend {
color: #00c;
}
</style>
</head>

<body>
<fieldset>
<legend>Select Font</legend>
<form name="foobar">
<div>
My font:<br>
<input type="text" name="field" size="25" onkeypress="if(event.keyCode==8) { listSearch(this.form); }" onkeyup="listSearch(this.form)"><br>
<select name="list" size="1">
<option value="">Select font</option>
<option value="Algerian">Algerian</option>
<option value="Arial">Arial</option>
<option value="Arial Black">Arial Black</option>
<option value="Arial Narrow">Arial Narrow</option>
<option value="Courier">Courier</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Trebuchet MS">Trebuchet MS</option>
<option value="Verdana">Verdana</option>
</select><br>
<br>
<input type="button" value="Foobar">
</div>
</form>
</fieldset></body>
</html>


Type something in the input field, for example "arial narrow". Watch the select field as you type. Then delete the text, type something else, and so on.

Purple Martin

10:06 pm on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice code DrDoc.

waxbird, you might find that when you've copy'n'pasted the code, you'll have to replace the pipe characters (the ¦¦ ones) to make it work.

waxbird

8:24 am on Feb 4, 2004 (gmt 0)

10+ Year Member



thanku sir.

waxbird

8:37 am on Feb 4, 2004 (gmt 0)

10+ Year Member



nice code,i'm in china and use gb2312,i have to trans ¡°gbcode¡± to ¡°spellcode¡± where in "option's value".but i think chinese will become a standard coding language in future:)

DrDoc

4:45 pm on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i think chinese will become a standard coding language in future

"What did you use to build such a marvelous page -- HTML with PHP? XML with Perl?"
"Chinese!"

;)

waxbird

3:36 pm on Feb 7, 2004 (gmt 0)

10+ Year Member



Dear DrDOC,i just only make some form for asp page .
as you see,i 'm not good at english:)
=======================================
when you investigate language,you will find english can use 26 spell out all word,but chinese can use 4000-5000 word spell out all you want to say.it's a limit concourse,can be coding for artificial intelligence£º¡³

DrDoc

5:14 pm on Feb 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, I wasn't trying to make fun of you, and I apologize if that's how you took it. Yes, I know Chinese has far more "characters". I read somewhere that you need to know at least 50,000 to be able to read the average newspaper completely! :o