0

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
}
1
  • By the way, you use double equal signs when doing a comparison. A single equals sign is the assignment operator. Commented Dec 23, 2011 at 19:01

3 Answers 3

2

From the val() documentation,

The correct way to set a value is,

$("input[title='name']").val('');

http://jsfiddle.net/GDVt6/5/

Sign up to request clarification or add additional context in comments.

Comments

1

Change your function to:

function clearID()
{
    $("input[title='name']").val('');
    $("input[title='email']").val('');
}

Comments

0
$("input[title='name']").val("");

the same for the email

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.