JQuery variable if statement error -
i trying check whether content user has submitted contains correct information. doing adding inputted context variable [code] , trying if else catch see whether matches want. [strong] variable.
however, not appear working, can shed light on this? please see below code.
$(document).ready(function() { $('#button-bold').click(function() { var code = jquery("textarea#bold-code").val(); var $pass = "congratulations, have entered correctly"; var $fail = "oops, again, can see have gone wrong?" var $strong = "<strong>recreate preview exactly</strong>"; if (code == strong) { alert(pass); $('#bold-output').append(code) }else { alert(fail); } }); });
thank in advance.
you've got mismatched variable names , without dollars - you're defining $strong
, $pass
, $fail
leading dollars using strong
, pass
, fail
without dollar.
(as aside, see dollar prefix on javascript variables means contain jquery selectors, e.g.
var $output = $('#bold-output');
rather general data - that's 1 convention.)
Comments
Post a Comment