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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate listbox value on submit 1

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,

I have the following code that I came across on this forum which should validate the entry in a listbox and if it equals "select type" which is the default value then it should alert the user and not submit the record.

However all that is happening is that on clicking the submit button it does appear to change the color to red momentarily but then carries on and submits the record.

Could someone explain where i am going wrong please

Code:
<script language="javascript">

function colorchange(divid, color)
{
  var colchg = document.frmInsertFile.all(divid);
  colchg.style.color = (color);
}

function validateform ( )
{
  //This sets the colors back to black in case they previously had been changed to red.
  colorchange("lstType", "black");

    var valid = true;
    var errmsg = "";

        if ( document.frmInsertFile.lstType.value == "Select Type" )
        {
                errmsg = errmsg + "Please Select A Valid Type." + "\r\n";
                colorchange("lstType", "red");
                valid = false;
        }
       
   return true;
}
</script>

and I have this for the submit
Code:
<form ACTION="<%=MM_editAction%>" METHOD="POST" id="frmInsertFile" name="frmInsertFile" onsubmit="return validateform()">

Regards

Paul

 
BabyJeffy,

Sorry I have not replied earlier, I have been offline for a couple of days.

Thanks for your response, your answer did the trick

a "Star" on it's way

Regards

Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top