Hello all!
I am currently working on the checkout screen for a shopping cart. I want to have a dropdown such as "Would you like to use saved Billing information?" if they have saved info to their account before. If they choose an existing address, I'd like to hide the fields so they don't get confused and think they need to enter anything.
The "options" will always have numeric values (0, 1, 2, 3, etc.)
Here is what I have HTML wise:
-
- <div id="existing_Billing">
- <h1>Billing Info</h1>
- <p>Would you like to use a saved credit card?</p>
- <select name="ucc_ID" class="existing_shipping" id="billing">
- <option value="NO">Select a Card</option>
- <option value="0">Mastercard</option>
- <option value="1">Visa</option>
- <option value="2">Discover</option>
- <option value="NO">No, use the info entered below</option>
- </select>
-
- <div id="form_billing">
- <div class="left">
- <div class="form_element">
- <label for="username">Username</label>
- <div class="input_box">
- <input id="username" name="username" type="text" class="text_input" />
- </div>
- <div class="clear"></div>
- </div>
- </div>
- <div class="left">
- <div class="form_element">
- <label for="password">Password</label>
- <div class="input_box">
- <input id="password" name="password" type="password" class="text_input" />
- </div>
- <div class="clear"></div>
- </div>
- </div>
- <div class="left">
- <div class="form_element">
- <label for="email">Email Address</label>
- <div class="input_box">
- <input id="email" name="email" type="text" class="text_input" />
- </div>
- <div class="clear"></div>
- </div>
- </div>
- </div>
- <div class="clear"></div>
- </div>
- </div>
I am pretty new to jQuery so here is the script I wrote, but sadly it isn't working. Can anyone help me make this work or show me a better way to achieve it?
- <script type="text/javascript">
- $(document).ready(function(){
-
- // assign id to js variable
- var billing = $("#billing");
-
- // if we changed the value...
- $(billing).change(function(){
-
- // evaluate whether its a number or not
- if (isNaN( $(billing).val() )) {
- // It isn't a number
- } else {
- // It is a number
- $('#form_billing').hide();
- }
- }
-
- });
- </script>