I have a project in which I have to set shipping address for online shopping. For paying, payment option are various credit cards for example: paypal, visa etc. so payment option is a drop down menu.
I have two labels namely "creditcard no" and "ccv". these should be hidden initially. Once payment option (from dropdown) is chosen, those two labels should appear.
$(document).ready(function() {
$('.nav-toggle').click(function() {
//get collapse content selector
var collapse_content_selector = $(this).attr('href');
//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function() {
if ($(this).css('display') == 'none') {
//change the button label to be 'Show'
toggle_switch.html('Show');
} else {
//change the button label to be 'Hide'
toggle_switch.html('Hide');
}
});
});
});
.round-border {
border: 1px solid #eee;
border: 1px solid rgba(0, 0, 0, 0.05);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
padding: 10px;
margin-bottom: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<section class="round-border">
<div>
<button href="#collapse1" class="nav-toggle">credit card</button>
</div>
<div id="collapse1" style="display:none">
<label>
Payment Option
<select name="credit">
<option value="paypal">Paypal</option>
<option value="Visa">Visa</option>
<option value="Visa">Master Card</option>
<option value="Discover">Discover</option>
<option value="American Express">American Express</option>
<option value="Alipay">Alipay</option>
</select>
</label>
<br>Card Number:
<input type="text" size="24" maxlength="20" name="cc_number" onBlur="
cc_number_saved = this.value;
this.value = this.value.replace(/[^\d]/g, '');
if(!checkLuhn(this.value)) {
alert('Sorry, this is not a valid number - Please try again!');
this.value = '';
}
" onFocus="
// restore saved string
if(this.value != cc_number_saved) this.value = cc_number_saved;
">
<input type="submit" type="submit" name="submit" value="Ok">
<br>ccv:
<input type="text" name="ccv" required>
<br>
</div>
</section>
</body>