Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help to find error (alert box not appearing)

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
US
I have the following code but the alert pop up did not appear when I leave the compulsory fields empty. Everything looks OK to me because it was working some time ago but I am not sure if I changed something and it can't work now. Can someone please point out the error to me?


Code:
<html>

<font face=tahoma size=3>

<script type="text/javascript">

function validate_required(field,alerttxt)
{
    with (field)
    {
        if (value=="")
              {alert(alerttxt);return false}
        else {return true} 
    }
}

function validate_length(field, max_length, alerttxt)
{
    with (field)
    {
        if (value.length>max_length)
            {alert(alerttxt);return false}
        else {return true}    
    }
}


function validate_form(thisform)
{
    with (thisform)
    {
        if (validate_required(NAME,"Please Enter Subcontractor Name")==false)
             {NAME.focus();return false}
    
        if (validate_length(NAME, 30, "You have entered " + NAME.value.length + " characters for Subcontractor Name\nPlease enter less than 30 characters")==false)
            {NAME.focus();return false}
    
        if (validate_required(CATEGORY,"Please Enter Category")==false)
             {CATEGORY.focus();return false}
    
        if (validate_length(CATEGORY, 25, "You have entered " + CATEGORY.value.length + " characters for Category\nPlease enter less than 25 characters")==false)
            {CATEGORY.focus();return false}
            
        if (validate_length(REF_ID, 30, "You have entered " + REF_ID.value.length + " characters for Reference ID\nPlease enter less than 30 characters")==false)
            {REF_ID.focus();return false}
        
        if (validate_length(ADDRESS, 80, "You have entered " + ADDRESS.value.length + " characters for Address\nPlease enter less than 80 characters")==false)
            {ADDRESS.focus();return false}
        
        if (validate_length(CONTRACT, 50, "You have entered " + CONTRACT.value.length + " characters for Contract\nPlease enter less than 50 characters")==false)
            {CONTRACT.focus();return false}
        
        if (validate_length(SE, 250, "You have entered " + SE.value.length + " characters for Supplier Enabling\nPlease enter less than 250 characters")==false)
            {SE.focus();return false}
    }
    
}

function validate_form2(thisform)
{
    with (thisform)
    {
        if (validate_required(NAME,"Please Enter Subcontractor Name")==false)
             {NAME.focus();return false}
    
        if (validate_length(NAME, 30, "You have entered " + NAME.value.length + " characters for Subcontractor Name\nPlease enter less than 30 characters")==false)
            {NAME.focus();return false}
    
        if (validate_required(YEAR,"Please Enter Year")==false)
             {YEAR.focus();return false}
    
        if (validate_length(YEAR, 5, "You have entered " + YEAR.value.length + " characters for Year\nPlease enter less than 5 characters")==false)
            {YEAR.focus();return false}
    
        if (insert_subcon_ratings_records.RATING.value > 100)
        {
            mesg = "You have entered " + insert_subcon_ratings_records.RATING.value + " for Rating\n"
            mesg = mesg + "Please enter a number less than 101."
            alert(mesg);
            insert_subcon_ratings_records.RATING.focus();
            return (false);
        }
    }
    
}

</script>



<u><b><font size=4>Subcontractor Records: </font></b></u><br>
<form name="insert_subcon_records" method="Post" action="insert_subcon_records.asp" onsubmit="return validate_form(this)">
<table>
<tr><td width=180><font color=red>*</font>Subcontractor Name: </td>
<td><input type=text name="NAME" size="50"></td></tr>
<tr><td><font color=red>*</font>Category: </td>
<td><input type=text name="CATEGORY" size="50"></td></tr>
<tr><td>Reference ID: </td>
<td><input type=text name="REF_ID" size="50"></td></tr>
<tr><td>Address: </td>
<td><textarea name="ADDRESS" cols="38" rows="2"></textarea></td></tr> 
<tr><td>Contract: </td>
<td><textarea name="CONTRACT" cols="38" rows="5"></textarea></td></tr> 
<tr><td>Supplier Enabling: </td>
<td><textarea name="SE" cols="38" rows="5"></textarea></td></tr> 
</table><br>
<input type="submit" name="submit_subcon_records" value="Submit Subcontractor Records">
<input type="reset" name="reset" value="Reset">
</form>

<form name="insert_subcon_ratings_records" method="Post" action="insert_subcon_ratings_records.asp" onsubmit="return validate_form2(this)">
<table>
<tr><td width=180><font color=red>*</font>Subcontractor Name: </td>
<td><input type=text name="NAME" size="50"/></td></tr>
<tr><td><font color=red>*</font>Year: </td>
<td><input type=text name="YEAR" size="50"/></td></tr>
<tr><td>Rating/100: </td>
<td><input type=text name="RATING" size="50"/></td></tr>
</table><br>
<input type="submit" name="submit_subcon_ratings_records" value="Submit Ratings Records">
<input type="reset" name="reset" value="Reset">
</form>

<font color=red>* = compulsory field</font>


</font>

</body>

</html>
 
instead of this:

Code:
if (validate_required(NAME,"Please Enter Subcontractor Name")==false)

try this (and change it for ALL lines)

Code:
if (validate_required(elements[NAME],"Please Enter Subcontractor Name")==false)

note: your code worked as-is in firefox.



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
It worked as is in IE6 also.
But as I said in the ASP forum, you are not testing when they LEAVE a field, you are only testing when the submit button is pressed. Your code is not setup to test field by field, only all at once.



Stamp out, eliminate and abolish redundancy!
 
Sorry?
Have you been casting curses on me again? I'll send my penguins against you.

Stamp out, eliminate and abolish redundancy!
 
Hi cLFlaVA

Thanks for the suggestion but it still cannot work. There is still no pop up alert.
 
omoo, what do you expect to happen? That if someone does not fill in the field correctly and move to the next field it will give an alert? That is what is sounds like you are expecting.

Your validation function does not execute until the Submit button is clicked at which time if the required field is not filled in correctly it does pop up an alert box.
Is this what you expect to happen but it is not on your system? Cause it is working in IE for me and FF for cLFlaVA.


Stamp out, eliminate and abolish redundancy!
 
Yes, I am expecting to have a pop up when I fill in the entire form but leave out the required fields. But in my browser, it is not working! And I don't know why
 
Flush your cache also in case your browser is still giving you the old version.


Stamp out, eliminate and abolish redundancy!
 
I have set to java scripting enabled and flush out the cache by clearing the history but it still doesn't work. I am using IE6.

When I click on submit with empty required fields, it go straight to the error message page:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC driver for Oracle][Oracle]ORA-01400: cannot insert NULL into ("DWH_SF"."SUBDB_SUBCON_RATING"."YEAR")

/sf1/subcontractor_database/insert_subcon_ratings_records.asp, line 19

it should have the pop up.
 
You need to Delete Files rather than just clearing the history. The history is just the recent links list, the cache consists of copies of the pages you have visited and it may be delivering an old copy rather than looking for the new version.
You can also do View\Source to see if the source code from the page that loaded is the same as the one you expect to be loading.


Stamp out, eliminate and abolish redundancy!
 
alright, i finally found out the reason. the source code is different from the one i pasted here. there are some small errors in the script which i have corrected now and it works. thanks all for the replies!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top