I want to clear my default value in two input fields before submitting them.
But this don’t work…
<form action="page.html" id="myForm">
<input type="text" value="Firstname" name="firstname" id="firstname">
<input type="text" value="Lastname" name="lastname" id="lastname">
<input type="submit">
</form>
<script>
$(document).ready(function() {
$("myForm").submit(function() {
if($('#firstname').val() == "Firstname")
$('#firstname').val() = "";
if($('#lastname').val() == "Lastname")
$('#lastname').val() = "";
return true;
});
});
</script>
I don’t want to clear them both on focus.
I cant use html5.
val is a function, you can’t use it like this.
Try instead :