Jump to content

Changing text field value


sonicthehedgehog

Recommended Posts

How do I change this so that it updates the value of a text field when particular number (credit card)?

$("span#type").removeClass().addClass("card " + card.type).fadeIn('fast');

I want it to change the value of text field with the id payment-card to the card type which is determined by the card number. That bit I've already done but I don't know how to change the text value too.

The card types are

SOLO

VISA

AMEX

MASTER

DINER

Link to comment
Share on other sites

It's already using a text field in the example, you type into the text field. You target the text field and call the detectCard method on it to do the auto-detection, and use the cardChange event to update your page when the card number changes. That's what they show here:

$("input#cardNumber").detectCard().on("cardChange", function(e, card) {}
input#cardNumber is their text field, they call the detectCard method on that field, and then attach a cardChange handler to update the page when the card number changes. The card object contains information about the number and card type they entered, that gets passed to the cardChange handler. You can use console.log(card) to send that card object to the developer console so you can see all the properties and methods on it, and you can write whatever other code in the handler to update the page however you want, like putting the card type in a hidden input.
Link to comment
Share on other sites

I would have thought that you could create a hidden input

<input type="hidden" value="" id="card_type_text" name="card_type_text">

Then use code similar to

$("input#cardNumber").detectCard().on("cardChange", function(e, card) {$("input#card_type_text").val(card.type).toUpperCase();});
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...