Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have this on my HTML and want to change the color of

on javascript :

XML
<td class="namecaption"><label for="name">Name:</label></td>
      <td><input id="name" name="name" type="text" placeholder="John"></td>
      <td  class="namecaption"><p id="nmerr" > (Required)</p></td>


This is what is in my javascript:

C#
function validate(){
    var strname = document.details.name.value;
        //Check if user entered input name
    if(strname ==""){
        window.alert("enter name");
        document.details.name.focus();
        document.getElementById("nmerr").style="color: red";
        }

Can someone please advice me on my function, Thanks

Posted

1 solution

Try this:
JavaScript
document.getElementById("nmerr").style.color = "red";
 
Share this answer
 
Comments
Dunisani 27-May-11 3:44am    
Thanks it works perfect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900