开发者

How do I change the Input type Placeholder holder property via Javascript?

开发者 https://www.devze.com 2023-01-03 19:48 出处:网络
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 vi

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号