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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript form submits on same page

    Hi-

    I have a small problem with the javascript part of a template to template adaptation... I have two forums, when they are submitted they are first checked by some javascript in the code. The problem is that they get mixed up. When I put data into the support form I get a no username error. When I put login info it sends it to support...

    Never used javascript before, can just understand what Im looking at but I have no idea how to fix this problem.

    I tried making a iframe but Ive never been a fan of them. Plus when I put in an iFram it messes with my sensitive template.

    Any help appreciated

    Code:
    <script language=javascript>
    function checklogin() {   
      if (document.loginform.username.value=='') {
        alert("Please enter your username!");
        document.loginform.username.focus();
        return false;
      }
      if (document.loginform.password.value=='') {
        alert("Please enter your password!");
        document.loginform.password.focus();
        return false;
      }
      return true;
    }
    </script>
    
    <div id="title">
    <form method=post name=loginform onsubmit="return checklogin()">
    <input type=hidden name=a value='do_login'>
    user<input type=text name=username class=inpts size=15>
    pass<input type=password name=password class=inpts size=15>
    <input type=submit value="Login" class=sbmt size=15>
    </div>
    <UL>
    <div id="content1">
    
    <h3>Support Form:</h3><br>
    
    
    <script language=javascript>
    
    function checkform() {
      if (document.mainform.name.value == '') {
        alert("Please type your full name!");
        document.mainform.name.focus();
        return false;
      }
      if (document.mainform.email.value == '') {
        alert("Please enter your e-mail address!");
        document.mainform.email.focus();
        return false;
      }
      if (document.mainform.message.value == '') {
        alert("Please type your message!");
        document.mainform.message.focus();
        return false;
      }
      return true;
    }
    
    </script>
    
    <form method=post name=mainform onsubmit="return checkform()">
    <input type=hidden name=a value=support>
    <input type=hidden name=action value=send>
    
    <table cellspacing=0 cellpadding=2 border=0>
    <tr>
     <td>Your Name:</td>
     <td><input type="text" name="name" size=30 class=inpts></td>
    </tr>
    <tr>
     <td>Your Email:</td>
    
     <td><input type="text" name="email" size=30 class=inpts></td>
    </tr>
    <tr>
     <td colspan=2>Message:<br><br><textarea name=message class=inpts cols=45 rows=4></textarea>
    </tr>
    <tr>
     <td>&nbsp;</td>
     <td><input type=submit value="Send" class=sbmt></td>
    </tr></table>
    </form>

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Your html is rather invalid.
    You should be quoting your attributes, too, just to be safe, even though I don't think it's technically required for the more forgiving doctypes. Also, be aware that if you aren't specifying a doctype, it defaults to quirks mode.

    Your main issue is a missing </form> tag before the start of the next form.
    You should really run this through a validator before trying to troubleshoot the script. Invalid html often messes up script, plus it's not as cross-browser. Internet Explorer is more forgiving than most browsers when it comes to invalid html.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Invalid html... good one

    Stuck in a form ending tag and works well on firefox & IE

    The reason for the html being rather sloppy is because I had to cut a template into many files so that it would work with a downloaded script. (There were around 10 files I had to edit )


  •  

    Posting Permissions

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