SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Form validation

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Form validation

    I am trying to change the color of the text box..if it is left blank. can any one help me with this? <script type="text/javascript">
    function changeColor()
    {
    if(password_form.password_email.value == "")
    document.getElementById("passwd").style.background-color = "red";
    else
    document.getElementById("passwd").style.background-color = "white";
    }
    </script> <form name="password_form" action="" method="post" onsubmit="changeColor(this)"> Email: <INPUT type="text" size="25" maxlength="64" name="password_email"> <input type="image" name="mailpassword" border="0" src="/images/password_button.gif" > thanks
    Last edited by koushikgattu; Jan 10, 2008 at 22:57.

  2. #2
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by koushikgattu View Post
    I am trying to change the color of the text box..if it is left blank. I don't know about the Javascript. can any one help me with this? <script type="text/javascript">
    function changeColor()
    {
    if(password_form.password_email.value == "")
    document.getElementById("passwd").style.background-color = "red";
    else
    document.getElementById("passwd").style.background-color = "white";
    }
    </script> <form name="password_form" action="" method="post" onsubmit="changeColor(this)"> Email: <INPUT type="text" size="25" maxlength="64" name="password_email"> <input type="image" name="mailpassword" border="0" src="/images/password_button.gif" > thanks
    try
    document.getElementById("passwd").style.backgroundColor = "red";

  3. #3
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a rule of thumb, you want to avoid styling html with javascript. Create a class and place all an objects style within the class then switch out the class name as needed. Also, you might want to look up unobtrusive javascript.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •