-2

Here is my fiddle:

I have 3 text inputs, and also have one hidden input with some numbers as its value: <input type="hidden" name="" value="100,101,105,106,109,2">. Now I'd like to do this - when you click on 'Go' button it will randomly show one of those numbers as input values so all inputs will have value after clicking Go button. How can I do this ?

aiddev
  • 1,409
  • 2
  • 24
  • 56

1 Answers1

1

Just use following code: Demo

$("#goBtn").click(function () {
    var arr = $("#values").val().split(",");
    var random = arr.splice(parseInt(Math.random()*arr.length), 1)[0];
    $("#num1").val(random);

     random = arr.splice(parseInt(Math.random()*arr.length), 1)[0];
    $("#num2").val(random);

     random = arr.splice(parseInt(Math.random()*arr.length), 1)[0];
    $("#num3").val(random);

    return false;
});
Sherali Turdiyev
  • 1,745
  • 16
  • 29