Results 1 to 2 of 2

Thread: [RESOLVED] [JavaScript] Exit Sub Equivalent

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Resolved [RESOLVED] [JavaScript] Exit Sub Equivalent

    I was hoping that the bold text would trap an error and exit the function.
    However, the alert appears and the code continues and the form gets submitted
    Is return; not the equivalent of Exit Sub?

    Code:
    function CheckForm(){
    	//This should be the number of file upload boxes
    	var intDUTs = document.frmUpload.cboDUTs.value;
        //Loop through all the file upload boxes and make sure that they have .txt or .rid extensions
    	for (var i = 0; i < intDUTs; i++){
    		//Get the filename from each box
    		try{
    			var strFile = (document.forms['frmUpload'].elements['txtFileName' + i].value);
    		}
    		catch(err){
    			
    			//alert("Please select a file for all of the devices.");
    			alert("Error.");
    			return;
    		}
    		//Check for blank fields
    		// alert("strFile.length " + strFile.length);
    		// alert(strFile);
    		// if (strFile.length = 0 || strFile = ""){
    		if (strFile.length == 0){
    			alert("Please select a file for all of the devices.");
    			return;
    		}
    		//Get the extension from the filename
    		var strExt = strFile.substring(strFile.length - 3);
    		//alert("strExt = " + strExt);
    		//Check for RID or TXT files
    		if (strExt !== 'rid' && strExt !== 'txt'){
    			alert("Only data files in rid or txt can be uploaded.");
    			return;		
    		}
    		else {
    			//document.frmUpload.submit();
    		} 
    		document.frmUpload.submit();		
    	}
    
    }

  2. #2

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: [RESOLVED] [JavaScript] Exit Sub Equivalent

    I should have been using return false
    Where has the delete thread/post button gone?

Posting Permissions

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



Click Here to Expand Forum to Full Width