SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    calif
    Posts
    743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding this code to the form didn't work

    I copied this code, which successfully makes entering an email into my form mandatory, tweaked it slightly, hoping it would be enough to make adding a Contact Name mandatory, but it didn't work. What am I missing? You guidance will be appreciated. Thanks

    [CODE]
    <script type="text/javascript">
    function checkcontact(){
    var str=document.myform.contact_name.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if(filter.test(str))
    testresults=true;
    else {
    alert("Please input a valid contact name");
    return false;
    }
    </script>
    [CODE]

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Where are you calling the function checkcontact() from?

    Also you should be aware that alert() is only useful now for debugging as it displays additional checkboxes either for turning off alert dialogs or turning off JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    calif
    Posts
    743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply. I currently have this in my Form:

    <form action='form_handle.php' method='post' name='myform' onSubmit="return checkemail()">

    Should I add this:
    <form action='form_handle.php' method='post' name='myform' onSubmit="return checkcontact()">

    Also, I don't know what you mean by:
    "Also you should be aware that alert() is only useful now for debugging as it displays additional checkboxes either for turning off alert dialogs or turning off JavaScript."
    Could you please clarify?
    Thanks again


Bookmarks

Posting Permissions

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