Ajay
Ajay

Reputation: 3

change textbox border style at runtime

change textbox border style at runtime:

I have tried this code

 <script type="text/javascript">
    function validate()
    {
       alert("hello");
       document.getElementById("emailid").border.style="1px solid green";
       document.getElementById('emailid').border.style="1px solid green";
    }
    <script>

    <td>Email:</td><td> <input type="text" name="emailid" id="emailid" value="" onblur="validate();"  maxlength=125 /><br></td>

It its showing me alert box but the border of textbox is not changing help with a working tested code

Upvotes: 0

Views: 1404

Answers (3)

Ankit Agrawal
Ankit Agrawal

Reputation: 6124

please try this code

<script type="text/javascript">
function validate()
{
    alert("hello");
   document.getElementById('emailid').style.border="1px solid green";
}
</script>

Upvotes: 0

Andy Lastname
Andy Lastname

Reputation: 86

Your end script tag is <script> not </script> - which may be affecting things. Also I'd highly recommend you get JQuery or some other library as using them removes any cross browser inconsistencies (and makes the code you have to write shorter).

Upvotes: 0

yogi
yogi

Reputation: 19591

Do this

document.getElementById("emailid").style.border = "1px solid green";
document.getElementById("emailid").style.border = "1px solid green";

instead of

document.getElementById("emailid").border.style = "1px solid green";
document.getElementById("emailid").border.style = "1px solid green";

Upvotes: 1

Related Questions