Reputation: 25
So I'm trying to create a kind of "keygenerator" for my project, so I'm using this code in a script inside of a Bootstrap project:
var keyWA = 1 + Math.floor(Math.random() * 4);
var keyA = 1 + Math.floor(Math.random() * 4);
$("#buttonWA").click(function(){
if (keyWA == 1) {
$("input[name=inputWA]").val(2405-3443-9893-5346);
} else {
$("input[name=inputWA]").val(2350-8496-2225-4682);
});
But it's not working. It does not put anything on the input. Am I doing something wrong?
Upvotes: 0
Views: 67
Reputation: 20737
Yes. Put single quotes in .val() because it is not a pure integer/float
$('input[name="inputWA"]').val('2350-8496-2225-4682');
also check out how I quoted $('input[name="inputWA"]')
EDIT:
$( ' input[name= " inputWA " ] ' )
// ^single ^double ^double ^single
Upvotes: 1
Reputation: 146191
You missed a bracket
$("#buttonWA").click(function(){
if (keyWA == 1) {
$("input[name=inputWA]").val(2405-3443-9893-5346);
} else {
$("input[name=inputWA]").val(2350-8496-2225-4682);
} //<-- this one is missing
});
Also, wrap 2405-3443-9893-5346
in quotes like '2405-3443-9893-5346'
.
Upvotes: 1