I'm using a simple HTML5 form adapted for iPhone, and I want to show error alerts with开发者_运维问答in 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!
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>
精彩评论