Thread: check if empty
View Single Post
  #9 (permalink)  
Old March 8th, 2004, 09:48 AM
joefawcett's Avatar
joefawcett joefawcett is offline
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well no-one suggested you change it to a submit button:), when I said 'manually' I meant by using JavaScript rather than HTML.
If you do that then you'll need to return true if you want the default action to happen, in this case submit, or false to prevent it. Then move the validation code to the onsubmit event of the form:
Code:
<html>
<head>
    <title>Testing</title>
    <style>
        #textbox {position:absolute; left:200px};
    </style>
    <script>
    function check(textbox)
    {
        if(textbox.value == "")
        {
            alert("Please enter telephone number");    
            //textbox.select();
            text.focus();
            return false;
        }
        return true;
    }
</script>
</head>
<body onload="document.myform.telephone.focus();">
<form name="myform" onsubmit="return check(document.myform.telephone)">
Telephone No. <input id="textbox" type="text" name="telephone" ><br><br>
<input type="submit" value="Submit"> <br><br>
</form>
</body>
</html>
--

Joe
Reply With Quote