Friends,
I am new to javascript and currently i m wrking with form validation. I facing breaks in that I want to show warning message when a user lefts name field as empty. This works good but when i want to move to next field still the warning message is displaying even though the field filled with text value:confused:. Here is my code. Please help me with ur ideas.

type="text/javascript">

function validate_form()
{
var a=document.forms["form1"]["fname"].value;
var b=document.forms["form1"]["lname"].value;
var search = -1;
var temp;

if(a.trim().length==0)
{
document.getElementById("f_name").innerHTML="* Field is empty";
}

else if(search!=a.search(" "))
{
document.getElementById("f_name").innerHTML="* Please enter your first name without spaces";
}

else if(b.trim().length==0)
{
document.getElementById("l_name").innerHTML="* Field is empty";
}

else if(search!=a.search(" "))
{
document.getElementById("l_name").innerHTML="* Please enter your last name without spaces";
}

else
{
alert("Thanks");
}

}
</script>


<style type="text/css"></style></head>
<body>



<form id="form1">
First Name*<input type="text" name="fname" id="fname"> <span id="f_name" style="color:red"></span> </br>

Last Name*<input type="text" id="lname"><span id="l_name" style="color:red"></span></br>


email&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="email" id="email"><span name="e_mail"></span></br>

New Password <input type="password" id="pwd"><span name="pwd1"></span></br>

Confirm Password<input type="password" id="conf_pwd"><span name="pwd2"></span></br>

<input type="button" id="button" value="submit" onclick="validate_form()" style="

</form>