Reputation: 411
Okay, so I'm still learning here.
Created a jsfiddle http://jsfiddle.net/JustJill54/GDVt6/ that will toggle visibility on name and email fields based on Y/N anonymous drop down. I wrote a function to clear the contents of the name and email fields if they have existing values.
To test it, I put a default value into the name, but the value of the name field is not being reset to an empty string as I specified in my function. Can anyone tell me why the name input is not being blanked out?
Many Thanks!
JavaScript:
function clearID ()
{
$("input[title='name']").val() == '';
$("input[title='email']").val() == '';
}
if ($("select[title='anonymous']option:selected").val() !== "Yes") {
$(".anon").toggle();
$("select[title='anonymous']").change(function() {
//$(".anon").toggle();
clearID();
$(".anon").toggle();
}); //close anonymous.change
}
Upvotes: 0
Views: 124
Reputation: 13853
From the val() documentation,
The correct way to set a value is,
$("input[title='name']").val('');
Upvotes: 2
Reputation: 29870
Change your function to:
function clearID()
{
$("input[title='name']").val('');
$("input[title='email']").val('');
}
Upvotes: 1