hi all,

i am new to javascript
i was trying to passe text input to javascript. but code is not working here is the code

<script type="text/javascript">
function val(){
     
  if(document.a.email.value=="" ||document.a.email.value==null ){
    alert("sssss");
    return false;
   }
    if(document.a.email.value!="" ||document.a.email.value!=null ){
    alert("sssss"+document.a.email.value);
   return true;
 }
} 
</script>

and here is the HTML code,

<form action="a.php" method="POST" onsubmit="return val();">
     
        <strong>E-Mail Address</strong> *</td><td><input name="email" type="text" value="" />
        
        <input type="submit" value="submit"  />
    </form>

can anybody tell me the reason not to view the alert message..

and i want if the email is null to stop submiting the data to a.php
thx.

you forgot to give name and id to form. Here is proper code.

<form name='a' id='a' action="a.php" method="POST" onsubmit="return val();">
if(document.a.email.value!="" ||document.a.email.value!=null )

That condition is always true - you should AND any NOT conditions in general.

also you can probably pass the this keyword to return val() and use that in your function for portability.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.