Problem with stopping form submission

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashsa
    New Member
    • Feb 2007
    • 45

    Problem with stopping form submission

    Hi all

    Am trying to validate a form onsubmit. And all the validation functions are working fine. I have assigned different type of validation functions to be called on clicking each input type="image"

    The problem is when one button (image) has been clicked and an alert is given, after that whatever button (image) i click shows the same validation alert instead of showing its own validation error ..

    Seems the problem is due to that i stop the form from being submitted by returning false..

    Any help will be highly useful ..

    Many Thanks in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Show your code.

    Comment

    • ashsa
      New Member
      • Feb 2007
      • 45

      #3
      Originally posted by acoder
      Show your code.
      The code goes this way :

      Code:
      <script>
      function validSearchString()
      {
      	var str=document.getElementById('stringToSearch').value;
      	if(str.length<3)
      	{
      		return false;
      	}
      	else
      		return true;
      }
      
      function validPresType()
      {
      	if(document.getElementById('<%=PrescriptionHelper.PRESCRIPTION_TYPE_RADIO_BUTTON_NAME%>').selectedIndex==0)
      		return false;
      	else
      		return true;
      }
      
      function validDrug()
      {
      	if(document.getElementById('prescriptionDrug').selectedIndex<1)
      		return false;
      	else
      		return true;
      }
      
      function isPositiveInteger(val)
      {
      	if(val==null)
      		return false;
          if (val.length==0)
      		return false;
          for (var i = 0; i < val.length; i++)
      	{
      		var ch = val.charAt(i)
              if (ch < "0" || ch > "9")
      	        return false;
          }
          return true;
      }
      
      function validateForm()
      {
      	if(btnClicked=="addquote")
      	{
      		if(!validPresType())
      		{
      			alert("Please select the Prescription Type");
      			return false;
      		}
      		else if(!validDrug())
      		{
      			alert("Please select a Drug to add");
      			return false;
      		}
      	}
      	else if(btnClicked=="Go")
      	{
      		if(!validSearchString())
      		{
      			alert("Please provide at least three characters for your search");
      			return false;
      		}
      		
      	}
      	else if(btnClicked=="AmendQuote")
      	{
      		for(x=0;x<<%=prescriptionItems!=null?prescriptionItems.length:0%>;x++)
      		{
      			if(!isPositiveInteger(document.getElementById('build_quote_qty_'+x).value))
      			{
      				alert('Please enter a valid Quantity');
      				return false;
      			}
      		}
      	}
      }
      
      </script>
      <form name="SelectPrescription" method="Post" action="online_prescription_process.jsp" onsubmit="return validateForm()">
      ...
      ...
      ...
      </form>

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What about your submit buttons?

        Comment

        Working...