0

how do you validate a form soo there is no alerts all i need is image and words to display next to the text box when something incorrect has been typed in

5
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by Bachu
0

Create a div to next to the text box or any field where you want to display something like.

<div id ="err1" style = "display:none">error message</div>

In validation function

function val()
{
if(error_condition)
{
document.getElementById('err1').style.display = "block";
}
}
0

Create a div to next to the text box or any field where you want to display something like.

<div id ="err1" style = "display:none">error message</div>

In validation function

function val()
{
if(error_condition)
{
document.getElementById('err1').style.display = "block";
}
}

Thet's fine as far as it goes but you also need to hide error messages after each error is cleared by the user and the form is re-validated.

In addition, it's more typical to use spans (inline elements) rather than divs (block elements), but this will depend on the layout of the form and where you want the error messages to appear.

Adapting Mahavir's notation, we get:

function val(){
  document.getElementById('err_1').style.display = (error_condition_1) ? 'inline' : 'none';
  document.getElementById('err_2').style.display = (error_condition_2) ? 'inline' : 'none';
  document.getElementById('err_3').style.display = (error_condition_3) ? 'inline' : 'none';
}

Airshow

0

ya i want to validate the dropdown list.. validating without alert box my issue is that if not fill value statement appears(validated), if i fill the value the statement should disappear

0

Praba11,

Validating a dropwown list (a <select> element presumably) doesn't make any sense. Its value can only ever be that of one of the options offered - all of which should be 100% valid, otherwise something has gone horribly wrong in coding the HTML.

Have a think about what you really want, recompose your question and ask it in a new thread rather than tacking onto an old one.

Edited by Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.