Results 1 to 3 of 3

Thread: Run JavaScript function after validation

  1. #1
    Join Date
    Jul 2006
    Location
    Graham, NC
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Run JavaScript function after validation

    I have a JavaScript validation function that checks to make sure that each combobox has had a selection made in it. Here is that code:
    Code:
    function checkform() {
    	var TWIndex=document.TireDiameterForm.TireWidth.selectedIndex;
    	var SWIndex=document.TireDiameterForm.SideWall.selectedIndex;
    	var WDIndex=document.TireDiameterForm.WheelDiameter.selectedIndex;
    	if (TWIndex==0){
    		alert('There is a problem with the Tire Width field');
    		return false;}
    	else if (SWIndex==0) {
    		alert('There is a problem with the Sidewall field');
    		return false;}
    	else if (WDIndex==0) {
    		alert('There is a problem with the Wheel Diameter field');
    		return false;}
    	return true;
    }
    If this function returns true, I want this additional function to run. How do I do this? Thanks in advance.
    Code:
    function TireDiameter() {
       var mm=.0393701
       var w = document.TireDiameterForm.TireWidth.value;
       var s = document.TireDiameterForm.SideWall.value;
       var d = document.TireDiameterForm.WheelDiameter.value;
       var y = Math.round((((((w * s) / 100) * 2) * mm) + (d * 1)) * 100) / 100;
       document.TireDiameterForm.Result.value = y;}

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    function checkform() {
    	var TWIndex=document.TireDiameterForm.TireWidth.selectedIndex;
    	var SWIndex=document.TireDiameterForm.SideWall.selectedIndex;
    	var WDIndex=document.TireDiameterForm.WheelDiameter.selectedIndex;
    	if (TWIndex==0){
    		alert('There is a problem with the Tire Width field');
    		return false;}
    	else if (SWIndex==0) {
    		alert('There is a problem with the Sidewall field');
    		return false;}
    	else if (WDIndex==0) {
    		alert('There is a problem with the Wheel Diameter field');
    		return false;}
                TireDiameter(); //Calling the function just before you are going to return a true value from the validation function.	
                return true;
    }
    I think you just want to make sure that before making a call to TireDiameter() that your form validation was successful.

    If you look at the above code you'll reach the TireDiameter(); only if you are going to return a true and i think this will give you the same effect you wants after that function call it will return true. Here it won't make much difference whether you call the function before or after that return because you will call the function only if you are going to return a true value.

    If you are returning a false value you'll never reach the function calling step.

  3. #3
    Join Date
    Jul 2006
    Location
    Graham, NC
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Perfect. Thanks alot codeexploiter. This is my first attempt at JavaScripting so I still have LOADS to learn. Thanks again!

Bookmarks

Posting Permissions

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