Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help me find this error

    I am not sure what is wrong with this code, but even if there is an error it still submits the form. It should stop & not submit if the fields are blank, but it is just submitting the blank form.

    PHP Code:
        <script type="text/javascript" language=javascript>
        function checkform() {
          if (document.easy_memos.question.value=='') {
            alert("<?php echo JS_ALERT_USER_TEXT?>");
            document.easy_memos.question.focus();
            return false;
          }
          return true;
        }
        </script>
    If I put this in the code or php tags then you would have to scroll horizontal to see it all so I just posted it in plain text. This is the form line...
    <form name="easy_memos" onSubmit="return checkform()" action="http://localhost/TNPB/admin/help_center_data.php?category=1&page=1&action=insert" method="post">

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    I cannot really see what it could be. Maybe you have some double quote echoed by php? Can you show us what you get for the alert()-line when you say View > Page Source in your browser.

    Have you looked in the error console in FF?

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by koyama View Post
    I cannot really see what it could be. Maybe you have some double quote echoed by php? Can you show us what you get for the alert()-line when you say View > Page Source in your browser.

    Have you looked in the error console in FF?
    Just a few CSS errors in the error console. This is from the View Source:
    Code:
        <script type="text/javascript" language=javascript>
    	function checkform() {
    	  if (document.easy_memos.question.value=='') {
    		alert("Please enter a question!");
    		document.easy_memos.question.focus();
    		return false;
    	  }
    	  return true;
    	}
        </script>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Is this not the trouble?

    <script type="text/javascript" language=javascript>

  • #5
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Philip M View Post
    Is this not the trouble?

    <script type="text/javascript" language=javascript>
    That didn't seem to matter.

    I tested the script and it was working for me in both FF and IE. It blocked form submission just fine. So the error must be coming from somewhere else.

    I'm afraid you'll have to give us a link if you don't get it resolved.

    Here is the code I was testing with.
    Code:
    <html>
    <head>
    <script type="text/javascript" language=javascript>
    	function checkform() {
    	  if (document.easy_memos.question.value=='') {
    		alert("Please enter a question!");
    		document.easy_memos.question.focus();
    		return false;
    	  }
    	  return true;
    	}
    </script>
    </head>
    <body>
    <form name="easy_memos" onSubmit="return checkform()"
      action="http://localhost/TNPB/admin/help_center_data.php?category=1&page=1&action=insert"
      method="post">
    <input type="text" name="question">
    <input type="submit">
    </form>
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •