JavaScript problem

Discussion in 'OT Technology' started by XtremelyCanadian, Apr 23, 2003.

  1. XtremelyCanadian

    XtremelyCanadian I play hockey.....EH

    Joined:
    Jan 4, 2002
    Messages:
    1,801
    Likes Received:
    0
    Location:
    Edmonton,Canada
    Im doing validation for a project in javascript, and i seem to keep getting the error. When i submit a form and leave the input fields blank, the error message pops up, BUT it still redirects to the other page. With my other javascript once the message pops up it doesnt redirect.

    Here is the javascript code :
    <script language="javascript">
    <!--

    function Validate(TheForm)
    {

    var Price=document.TheForm.Price;
    var Year=document.TheForm.YearCur;

    var success = true;
    if(TheForm.Price.value == "")
    {
    alert("Please fill in a price");
    document.TheForm.Price.focus();
    success=false;
    }
    elseif(TheForm.YearCur.value == "")
    {
    alert("Please fill in a year");
    document.TheForm.YearCur.focus();
    success=false;
    }
    elseif (checkPrice(Price.value)==false)
    {
    alert("Please enter a valid price")
    Price.value="";
    document.TheForm.Price.focus();
    success=false;
    }
    elseif (checkYear(YearCur.value)==false)
    {
    alert("Please enter a valid year")
    YearCur.value="";
    document.TheForm.YearCur.focus();
    success=false;
    }
    input=x.YearCur.value
    elseif (input.length!=4)
    {
    alert("A Year is 4 characters in length! (ex. 1999)")
    document.TheForm.YearCur.focus();
    success=false;
    }
    return success;
    }

    Here is the form tag :

    <form name = 'TheForm' method = "post" action="<%=request.getContextPath()%>/servlet/Norwood.TaskMarshall" onsubmit="return Validate(this);">

    Here is the submit button :

    <input type='submit' name='submit' value='Add'>

    ANY SUGGESTIONS ???????
     

Share This Page