0

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.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by TomH.PG
0

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();">
0
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.

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.