Click to See Complete Forum and Search --> : Check Textbox


alexp_77
01-01-2004, 02:36 PM
Hello,
I'm Alex from Italy,
This my form....I have a combobox whith two values:

1. code
2. Description

and I have a text box.

I would want that, when was selected code in combobox, the textbox accepted only numbers, and when was selected description in combobox, textbox accepted everythings.

Thanks
Ale

olerag
01-01-2004, 04:50 PM
I can get something for you tommorrow morning if
someone else doesn't provide something sooner.

1 question - wouldn't a radio group object be better than
a combo box to control your textfield key events???

alexp_77
01-02-2004, 04:59 AM
for me the better choice is the combobox...for one problem of compatibility with a my program in visual basic...many thanks for the interest....
Alessandro

olerag
01-02-2004, 09:01 AM
Here's some code using a "combo" whose name is "selectObj"
and returns the value of "C" when the "Code" option is
selected.


<script type="text/javascript">
function numbersOnly(evt, val) {
if (isCode()) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
if ( (charCode >= 48 && charCode <= 57) || charCode == 8 || charCode == 9 || charCode == 13) {
return(true);
};
return(false);
}
return(true);
}

function isCode() {
var obj;
obj = document.forms[0].selectObj;
if (obj.options[obj.selectedIndex].value == "C") {
return(true);
}
return(false);
}
</script>


<input type="text" name="textObj" size="25" onkeypress="return numbersOnly(event,this.value)">

alexp_77
01-02-2004, 12:42 PM
Thank you very much....It's great!
Alessandro :D

olerag
01-02-2004, 12:54 PM
Your welcome - enjoy this spring's football season.