Topic: jQuery | Auto fill text input if left blank

I'm working on a page where users can come and write what they are believing God for in 2009. I have a small form where they can enter (a) What they're believing for and (b) their name.

I'm using ExpressionEngine, so the name is a required field (because it's really a comment). I want people to be able to leave the field blank if they want it to be anonymous. So is there a way preferably using jQuery that I can assign a value to that text input when it's left blank?

The page in work is here.

Last edited by Jim Arment (2009-06-23 08:51:57)

Re: jQuery | Auto fill text input if left blank

If it's a standard text input you could just insert something like "anonymous" in as value="anonymous". Then they can change it or leave it as they'd like. Otherwise you could do something like to change the value when they try to submit the form:

$('#SubmitButton').click( function() { 

          $("#name").val('anonymous'); 

} );

Assuming your submit button is #SubmitButton and your text input is #name.
Hope that's helpful!

Re: jQuery | Auto fill text input if left blank

Great, thanks