I have a button (named Benjamin):
<input type="submit" name="btn_submit" value="Next →" />
And on a click event it says ‘Loading’ and does cool stuff. However, if there is a problem, I want it to change back to its original text while displaying the error message elsewhere.
$('input[name=btn_submit]').click(function() {
$(this).val('Loading');
// Logicy Stuff...
// Error?
$(this).val('Next →');
return false;
});
Somehow, the literal text → is applied to the button, rather than the cool →. How do I fix this?
Html is evaluated with different rules that JavaScript is. Html entities only parsed by the html parser. Either use the unicode literal, like so:
Or better, keep track of the original value and then set it back:
Or perhaps even better, use HTML data attributes to store the states.
Then: