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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Credit card + Select box 1

Status
Not open for further replies.

fmrock

Programmer
Sep 5, 2006
510
US
I have a form that a user here will type in a credit card.

Based on teh first number in the text box. I would like it to select a specific card in the drop down list.

For example if the first digit is 4 i would like it to select Visa from the select box.
 
You can put an onkeyup event handler on the textbox where the numbers are typed in.

In the function that is called with the onkeyup you could grab the current value that is typed in the text field and based on that set the value of your select box.

Example:
Code:
<input type="text" onkeyup="grabCardSelection(this.value)"/>

The function would do the following:
Code:
function grabCardSelection(textNum) {
   var selectBoxObj = document.getElementById('objName');
   if (String(textNum).substr(0, 1) == '4') {
      selectBoxObj.value = "Visa";
      //This is assuming your values are named after
      //the card names
   }
}

That should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top