Here is my option code and text box
<select id="sel" class="form-control input-lg" data-live-search="true">
<option value="">-- Select Your Country--</option>
</select><br/><br/><br/>
<input type = "text" id = "txtName" class="form-control input-lg" />
</div>
This is my JSON code
[
{
"country":"First",
"coupon":["1","10","11"]
},
{
"country":"Second",
"coupon":"2"
},
{
"country":"third",
"coupon":"3"
},
{
"country":"fourth",
"coupon":"4"
},
{
"country":"fifth",
"coupon":"5"
}
]
i have populated JSON to dropdown and shown to text (input) box
$('#sel').append('<option value="' + value.coupon + '">' + value.country + '</option>');
$('#sel').change(function () {
var str = $("#sel").val();
$("#txtName").val(str);
}
What i need is when i select the value "First" in dropdown which has 3 numbers ["1","10","11"] i need it to be shown in random order 1 at a time in text box
I used below code to randomly generate it but i couldn't get desired result.Could anyone help me ?
Array.prototype.random = function (length) {
return this[Math.floor((Math.random()*length))];
}
// var randomcoupon = value.coupon.random(value.coupon.length);
Aucun commentaire:
Enregistrer un commentaire