Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  49] [ 7]  / answers: 1 / hits: 5531  / 10 Years ago, thu, march 6, 2014, 12:00:00

Here is the Demo



I am working in Javascript Validation. I want to give Separate colour for the text
Please enter Valid Email ID



When User Enter a wrong email id and press, there is one Error message will come. I want give red colour for this Error message. Only for this Error message i need red colour



HTML



<label id=message>We don't Spam. Promise</label> <br />
<input autocomplete=on type=text name=booking_email onkeyup=validate() id=SignupText class=InputSignup placeholder=Enter Your Email />
<input type=submit value=submit class=subButton onclick=submitEmail();/>


JAVASCRIPT



function validate()
{
var booking_email = $('input[name=booking_email]').val();

if(booking_email == '' ){
document.getElementById(message).innerHTML=We don't Spam. Promise;
}else if( /(.+)@(.+){1,}.(.+){2,}/.test(booking_email) )
{
document.getElementById(message).innerHTML=Your email is valid
if(event.which == 13){
submitEmail();
}
} else {
document.getElementById(message).innerHTML=Type your email id;

if(event.which == 13){
submitEmail();
}
}
}
function submitEmail()
{
var booking_email = $('input[name=booking_email]').val();
if(booking_email==)
{

document.getElementById(message).innerHTML=Please enter Your Email ID
}
else if( /(.+)@(.+){1,}.(.+){2,}/.test(booking_email) )

{
alert('success');

}

else {document.getElementById(message).innerHTML=Please enter Valid Email ID;}


}

More From » jquery

 Answers
3

just change



document.getElementById(message).innerHTML=Please enter Your Email ID


to



document.getElementById(message).innerHTML = <span style='color:red'>Please enter Your Email ID</span>;


wrapping the text with a span that has the color set to red ?


[#47121] Wednesday, March 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;