SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    -
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Validation Type Thing

    Does anyone have code that I can use to disallow 2 specific inputs in a form field?

    What I'm looking for is something that will not let you submit the form if the value for the textbox named "dom" was either "yourisp.com" or "aim.com". I really need the help on this one.

    -Josh

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <script>
    function checkValue() {
    var v=document.forms[0].dom.value;
    if (v=='yourisp.com' || v == 'aim.com')
    return false;

    }
    </script>
    <form onsubmit="return checkValue()">

    <input type="text" name="dom" value="">
    <input type="submit" name="submit" value="Send">
    </form>

    Is this what you're looking for?

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    -
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm looking for something more to the effect of popping an alert up saying "Invalid Domain Name - please correct it". How can I make the form part post to code.php (the file it will go to), not get?

    -Josh

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <script>
    function checkValue() {
    var v=document.forms[0].dom.value;
    if (v=='yourisp.com' || v == 'aim.com') {
    alert('Invalid Domain Name - please correct it');
    document.forms[0].dom.select();
    return false;
    }

    }
    </script>
    <form action="code.php" method="post" onsubmit="return checkValue()">

    <input type="text" name="dom" value="">
    <input type="submit" name="submit" value="Send">
    </form>

    action and method are basic form attributes.

    O'Reilly is coming out with a second edition of 'Dynamic HTML: the definitive reference' in August. You may find it worth the investment.


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
  •