/ Forside/ Teknologi / Udvikling / Java Scripts / Spørgsmål
Login
Glemt dit kodeord?
Brugernavn 

Kodeord  


Reklame
Top 10 brugere
Java Scripts
#NavnPoint
molokyle 5410
Klaudi 2799
smorch 2439
kim 1360
Harlekin 1134
bentjuul 984
gibson 800
severino 695
Random 675
10  konsulent.. 626
En "rigtig" Combobox
Fra : MKirsbo
Vist : 342 gange
200 point
Dato : 20-10-03 16:53

Hej,

Jeg skal have lavet en combobox på en hjemmeside. Med combobox forstås en dropdownbox hvori der også kan skrives, som i et almindeligt input felt.
Jeg ved at HTML ikke har en rigtig combobox, så jeg har prøvet med blandt andet WebFX.nu's udemærkede combobox Javascript. Denne er da også helt fin, men jeg skal have mulighed for at placere 2 comboboxe indenfor det samme div (hvilket ikke kan lade sig gøre i WebFX's script, så vidt jeg kan se).

Hvilke muligheder har jeg?

mvh Morten Kirsbo@clannies.com

 
 
Kommentar
Fra : smorch


Dato : 20-10-03 17:01

<SCRIPT LANGUAGE="JavaScript">

/*------------------------------------------------
Variables required for
fnChangeHandler_First() & fnKeyPressHandler_First()
for Editable Dropdowns
-------------------------- Subrata Chakrabarty 3.Jan.2003
*/


var PreviousSelectIndex_First = 0;
/* Contains the Previously Selected Index */

var SelectIndex_First = 0;
/* Contains the Currently Selected Index */

var SelectChange_First = 'MANUAL_CLICK';
/* Indicates whether Change in dropdown selected value */
/* was due to a Manual Click */
/* or due to System properties of dropdown */




/*------------------------------------------------
Functions required for Editable Dropdowns
-------------------------- Subrata Chakrabarty 3.Jan.2003 */




function fnChangeHandler_First(getdropdown)
{
PreviousSelectIndex_First = SelectIndex_First;
/* Contains the Previously Selected Index */

SelectIndex_First = getdropdown.options.selectedIndex;
/* Contains the Currently Selected Index */

if ((PreviousSelectIndex_First == (0)) && (SelectIndex_First != (0))&&(SelectChange_First != 'MANUAL_CLICK'))
/* To Set value of Index variables - Subrata Chakrabarty 3.Jan.2003 */
{
getdropdown[(0)].selected=true;
PreviousSelectIndex_First = SelectIndex_First;
SelectIndex_First = getdropdown.options.selectedIndex;
SelectChange_First = 'MANUAL_CLICK';
/* Indicates that the Change in dropdown selected
         value was due to a Manual Click */
}
}





function fnKeyPressHandler_First(getdropdown)
{
if(getdropdown.options.length != 0)
/*if dropdown is not empty*/
if (getdropdown.options.selectedIndex == (0))
/*if option the Editable field i.e. the FIRST option */
{
var EditString = EditMe_First.innerText;
/* Contents of Editable Option */

if (EditString == "--?--")
/* On backspace on default value of Editable option make Editable option Null */
EditString = "";

if ((window.event.keyCode==8 || window.event.keyCode==127))
/* To handle backspace - Subrata Chakrabarty 3.Jan.2003 */
{
EditString = EditString.substring(0,EditString.length-1);
/* Decrease length of string by one from right */

SelectChange_First = 'MANUAL_CLICK';
/* Indicates that the Change in dropdown selected
            value was due to a Manual Click */

}


/* Check for allowable Characters */
/*
The various characters allowable for entry into Editable option..
may be customized by minor modifications in the code (if condition below)
(you need to know the keycode/ASCII value of the character to be allowed/disallowed.
- Subrata Chakrabarty 3.Jan.2003
*/

if ((window.event.keyCode==46) || (window.event.keyCode>47 && window.event.keyCode<59)||(window.event.keyCode>62 && window.event.keyCode<127) ||(window.event.keyCode==32))
/* To handle addition of a character - Subrata Chakrabarty 3.Jan.2003 */
{
EditString+=String.fromCharCode(window.event.keyCode);
/*Concatenate Enter character to Editable string*/

/* The following portion handles the "automatic Jump" bug*/
/*
The "automatic Jump" bug (Description):
If a alphabet is entered (while editing)
...which is contained as a first character in one of the read-only options
..the focus automatically "jumps" to the read-only option
(-- this is a common property of normal dropdowns
..but..is undesirable while editing).
*/

var i=0;
var EnteredChar = String.fromCharCode(window.event.keyCode);
var UpperCaseEnteredChar = EnteredChar;
var LowerCaseEnteredChar = EnteredChar;


if(((window.event.keyCode)>=97)&&((window.event.keyCode)<=122))
/*if EnteredChar lowercase*/
UpperCaseEnteredChar = String.fromCharCode(window.event.keyCode - 32);
/*This is UpperCase*/


if(((window.event.keyCode)>=65)&&((window.event.keyCode)<=90))
/*if EnteredChar is UpperCase*/
LowerCaseEnteredChar = String.fromCharCode(window.event.keyCode + 32);
/*This is lowercase*/


for (i=0;i<(getdropdown.options.length-1);i++)
{ var ReadOnlyString = getdropdown[i].innerText;
var FirstChar = ReadOnlyString.substring(0,1);
if((FirstChar == UpperCaseEnteredChar)||(FirstChar == LowerCaseEnteredChar))
{
SelectChange_First = 'AUTO_SYSTEM';
/* Indicates that the Change in dropdown selected
value was due to System properties of dropdown */
break;
}
else
{
SelectChange_First = 'MANUAL_CLICK';
/* Indicates that the Change in dropdown selected
value was due to a Manual Click */
}
}
}

/*Set new value of edited string into the Editable field */
EditMe_First.innerText = EditString;
EditMe_First.value = EditString;
return false;
}
return true;
}
/*-------------------------------------------------------------------------------------------- Subrata Chakrabarty 3.Jan.2003 */

function fnLeftToRight(getdropdown)
{
getdropdown.style.direction = "ltr";
}

function fnRightToLeft(getdropdown)
{
getdropdown.style.direction = "rtl";
}

function fnDelete(getdropdown)
{
if(getdropdown.options.length != 0)
/*if dropdown is not empty*/
if (getdropdown.options.selectedIndex == (0))
/*if option the Editable field i.e. the FIRST option */
{
         getdropdown.options[getdropdown.options.selectedIndex].text = '';
}
}

</SCRIPT>
<body>

<FORM>
   <select name="tekst" style="width:250px;" onKeyDown="if(window.event.keyCode == 37){fnLeftToRight(this.form.tekst);}if(window.event.keyCode == 39){fnRightToLeft(this.form.tekst);}if(window.event.keyCode == 46){fnDelete(this.form.tekst);}if(window.event.keyCode == 8 || window.event.keyCode==127){window.event.keyCode = '';return true;}if(window.event.keyCode == 9){fnLeftToRight(this.form.tekst);}" onKeyUp="return false" onKeyPress = "fnKeyPressHandler_First(this.form.tekst)" onChange="fnChangeHandler_First(this.form.tekst)">
   <OPTION id="EditMe_First" name="EditMe_First" value="" style="COLOR:#ff0000;BACKGROUND-COLOR:#ffff00;" selected>--?--</option>
   <option value="Indbetaling kontant">Indbetaling kontant</option>
   <option value="Indbetaling dankort">Indbetaling dankort</option>
   
   </select>

</FORM>

Fyld selv resten ind i formularen(husk action="" name="" og så videre)

Mvh

sMorch

Du har følgende muligheder
Dette spørgsmål er blevet annulleret, det er derfor ikke muligt for at tilføje flere kommentarer.
Søg
Reklame
Statistik
Spørgsmål : 173637
Tips : 31664
Nyheder : 719565
Indlæg : 6383625
Brugere : 218258

Månedens bedste
Årets bedste
Sidste års bedste