Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Posts
    7

    Unanswered: Oh please bloomin validate!!!

    Im new to this ASP and Javascript thingy and so already got problems. I have a form with a text box on which i have used Javascript to validate so if nothing is entered an alert pops up.

    before my code for the form was:

    FORM onSubmit="return validate(this);"

    and the validation worked fine. In order to use the form properly I made it get a file. Now my code is

    FORM action="result.asp" method="get" onSubmit="return validate(this);"

    and now the pop up doesnt appear if nothing is entered. Instead

    result.asp?searchfield=

    gets appended to the url. Please help its driving me mad!!!

  2. #2
    Join Date
    Jan 2005
    Posts
    36
    What's happening is the form is being submitted now to result.asp, in the earlier version you were calling JS. The ?searchfield= is being appended because you have method = GET.

    Maybe do this

    <form name="myform" method="post" action="result.asp">

    Then on your submit button - call the validate Javascript

    The validate JS has the alerts if the entries are not correct.

    If they are correct then

    document.myform.submit();

    This will then submit your page to result.asp only if the form is filled out

  3. #3
    Join Date
    Jan 2005
    Posts
    7
    Ok now im confused.

    my form now has method="post" and a name="myform". I have put the "return validate(this);" in the submit button tag instead of the form tag. My JS code now reads:

    function validate(f){

    if(f.search.value==""){
    alert("Please enter details into search box");
    f.search.focus();
    return false;
    }
    return true;
    document.myform.submit()

    }

    I know im doing something wrong cos its still not working. Before u ask:

    Yes I am thick
    No i havent got a clue
    Yes i have never done this in my life before

  4. #4
    Join Date
    Jan 2005
    Posts
    36
    Do this,

    on your submit button make sure you have
    type="button"
    onclick ="validate()"

    then

    function validate(){

    if(document.myform.search.value==""){
    alert("Please enter details into search box");
    document.myform.search.focus();
    }
    else {
    document.myform.submit()
    }
    }

    Try that - it should work

  5. #5
    Join Date
    Dec 2003
    Posts
    454
    function validate() {
    if (document.searchForm.searchText.value == "") {
    alert("You did not enter the search keywords.");
    return false;
    }
    else
    return true;
    }

    <form action="result.asp" method="post" name="searchForm" onsubmit="if(validate()) document.searchForm.submit(); else false;">
    <input type="Text" name="searchText" value="">
    <input type="Submit" name="search" value="Search">

Posting Permissions

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