I'm trying to generate a random number into a text field. Unfortunately ID's are not an option here so I'm using classes as identifiers. I've tried a number of things but cannot seem to get this work.
HTML for input:
<div class="productAttributeRow productAttributeConfigurableEntryNumbersOnlyText">
<div class="productAttributeLabel">
<label>
<span class="name">
Hidden:
</span>
</label>
</div>
<div class="productAttributeValue">
<input type="text" class="Field validation" value="" size="5" />
</div>
</div>
I have tried:
var randomnumber = Math.floor(Math.random() * 11)
$('#BuyThis').click(function () {
$(".productAttributeConfigurableEntryNumbersOnlyText.productAttributeValue input[type="
text "]").val(randomnumber);
});
In the above scenario, #BuyThis is a button:
<a id="BuyThis" type="button" class="btn btn-small btn-warning" href="#product-options" data-toggle="modal">
However, it's not necessary this happen with a click, I just want a random number in the field before the form is submitted.
Also tried without the click:
$(function(){
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText.productAttributeValue input[type="text"]').val( randomnumber );
})
Another attempt:
function randomNumber(m, n) {
m = parseInt(m);
n = parseInt(n);
randomnumber = Math.floor(Math.random() * (n - m + 1)) + m;
('.productAttributeConfigurableEntryNumbersOnlyText.productAttributeValue input[type="text"]').value = randomnumber;
});
Tried various other functions and combinations to no avail.