Thread: check if empty
View Single Post
  #1 (permalink)  
Old March 7th, 2004, 07:38 AM
hosefo81 hosefo81 is offline
Authorized User
 
Join Date: Oct 2003
Location: KL, wilayah persekutuan, Malaysia.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default check if empty

when the user clicked the submit button, it will check if there is any value for the telephone textbox.If no value, then alert the user and stop submitting else submit the form.But my code below has does not work. Please help me correct it.
<html>
<head>
    <title>Testing</title>
    <style>
        #textbox {position:absolute; left:200px};
    </style>
    <script>
    function check(text)
    {
        if(!text.value))
        {
            alert("Please enter telephone number");
            text.select();
                     text.focus();
            return false;
        }
    }
</script>
</head>
<body onload="document.myform.telephone.select(); document.myform.telephone.focus();">
<form name="myform" >
Telephone No. <input id="textbox" type="text" name="telephone" ><br><br>
<input type="button" value="Submit" onclick="check(document.myform.telephone.value)"> <br><br>
</form>
</body>
</html>



Reply With Quote