views:

107

answers:

2

Hi,

I'm using a simple HTML5 form adapted for iPhone, and I want to show error alerts within the text fields themselves using the Placeholder property but I don't know how to access it via Javascript.

Here is a field example HTML code:

I want that the placeholder text (and maybe color?) will change in a javascript Validate function the form calls before it is submitted but I can't seem to change it no matter what concept I try.

Thanks!

A: 

It sounds like you're targeting the iPhone browser. Is this correct? If so, you'll find that it's not (yet) supported there.

http://diveintohtml5.org/forms.html#placeholder

Matt Ball
A: 

Got the answer!

Here is the javascript code you can use that goes with the HTML I wrote above:

function validate(theForm)
    {
        var name = theForm.name;
        if(name.value == "")
        {
            name.setAttribute('placeholder',"Please enter your name to continue");
            return false;
        }
return true;}

Here is the HTML input line in the form:

<input type="text" id="name" name="name" value="" placeholder="Click here to enter your full name" tabindex=1 /></div>
liorwn