Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2004, 04:48 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, but if you used the function I showed above the form will NOT submit.
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();
            Textbox.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
 
Old March 9th, 2004, 07:39 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oooh!Like this. Just one more questions.

if i have two or more textboxes and i would like to check them all before submitting(form validation).i type
onsubmit="return check(document.myform.telephone);return check(document.myform.name)"> and the first function works well but the second function doesn't function.
Why and how to solve it? i just want one check function to validate them.i believe because of the ; in the onsubmit.

 
Old March 9th, 2004, 08:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Just have one validate function that goes through all inputs that need validating and returns false as soon as it finds one that fails, otherwise return true at the end. There must be hundreds of validating scripts posted on the Web, instead of just thrashing about why not try to understand how it all works?


--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset Empty Check Coby Access VBA 2 April 27th, 2007 04:09 PM
best way to check for variable being empty crmpicco Classic ASP Basics 3 March 28th, 2006 12:11 PM
How to check for empty fields in a form. crmpicco Javascript How-To 7 February 15th, 2005 10:38 AM
How to check if you have an empty array Ciarano VB How-To 9 March 31st, 2004 09:17 AM
How to check if collection is empty Ciarano Beginning VB 6 2 March 5th, 2004 08:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.