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
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    alert with two forms

    Code:
    <form action="key1_action.htm" method="post">
      <input name="Key1" 
             value="" 
             type="text" 
             maxlength="20"
             size="17"><br>
    
      <input type="submit" value="Search key1">
    </form>
    
    <form action="key2_action.htm" method="post"> 
          <input name="Key2" 
               value="" 
               type="text" 
               maxlength="20"
               size="17"><br>
    
        <input type="submit" value="Search Key2">
    </form>
    I have two forms in a page by the code above.

    If user clicks the Search key1 sumbmit button without any entering,
    I like to make an alert saying "key1, please."

    And

    If user clicks the Search key2 sumbmit button without any entering,
    I like to make an alert saying "key2, please."


    Can I do it with your help?

    Thanks in Advance
    Get my greedy up

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function validate(f, index){
      var ele = f.elements["Key" + index];
      if (ele.value == "")
      {
        alert("Key" + index + ", please.");
        ele.focus();
        return false;
      }
      return true;
    }
    </script>
    </head>
    <body>
    <form action="key1_action.htm" method="post" onsubmit="return validate(this, 1)">
      <input name="Key1" 
             value="" 
             type="text" 
             maxlength="20"
             size="17"><br>
    
      <input type="submit" value="Search key1">
    </form>
    
    <form action="key2_action.htm" method="post" onsubmit="return validate(this, 2)"> 
          <input name="Key2" 
               value="" 
               type="text" 
               maxlength="20"
               size="17"><br>
    
        <input type="submit" value="Search Key2">
    </form>
    </body>
    </html>
    Last edited by glenngv; 12-08-2004 at 01:11 PM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, your code works fine.
    Get my greedy up


  •  

    Posting Permissions

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