SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,099
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    scripts wont play together and over my head

    Hi,

    I am trying to do form validation and make the submit button dissapear.

    This is for a photocontest and I really want the submit button to dissapear while the image uploads and also need the basic validation.

    both of these scripts work independantly but not together.

    I changed the variable names in the validate function but it didnt help.

    Code:
    function loading(whichElement,whichFunction,whichProperty,whichValue){
    	var ns6 = document.getElementById && !document.all;
    	var ie = document.all;
    	
    	var whichElementArray = whichElement.split(",");
    	var whichFunctionArray = whichFunction.split(",");
    	var whichPropertyArray = whichProperty.split(",");
    	var whichValueArray = whichValue.split(",");
    
    	for(var i=0; i<whichElementArray.length; i++){
    		if(ie){
    			if(whichFunctionArray[i] == "setTEXT"){	eval("document.all."+whichElementArray[i]).innerHTML = whichValueArray[i];}
    		}
    		else if(ns6){
    			if(whichFunctionArray[i] == "setTEXT"){	document.getElementById(whichElementArray[i]).innerHTML = whichValueArray[i];}
    		}
    	}
    }
    
    function validateme(what) {
    var pass=true;
    if (document.images) {
    for (j=0;j<what.length;j++) {
    var checkme=what.elements[j];
    if (checkme.name.substring(0,2)=="xx") {
    if (((checkme.type=="text"||checkme.type=="textarea")&&
    checkme.value=='')||(checkme.type.toString().charAt(0)=="s"&&
    checkme.selectedIndex==0)) {
    pass=false;
    break;
             }
          }
       }
    }
    if (!pass) {
    validatename=checkme.name.substring(2,30).toUpperCase();
    alert("Your "+validatename+" Is Required.");
    return false;
    }
    else
    return true;
    }
    I am calling the two functions like this

    onSubmit="return validateme(this);loading('output_div2','setTEXT','','<img src= ./loading.gif Uploading Image')"

    If anyone can help with this it will be muchly appreciated.

    Thanks
    Loren

  2. #2
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,099
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I just tried this
    Code:
    if (!pass) {
    validatename=checkme.name.substring(2,30).toUpperCase();
    alert("Your "+validatename+" Is Required.");
    return false;
    }
    else
    loading('output_div2','setTEXT','','<img src= ../b-cmn/loading.gif><b><font color=3F4C6B face=arial size=2> Uploading Image</font></b>')
    return true;
    
    }
    and removed the loading function call from the onSubmit part

    I just read the post about combining scripts and gave it a try and it works.

    I dont understand why it doesnt work in the first example though.

    cheers
    Loren

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont understand why it doesnt work in the first example though.
    Code:
    "return validateme(this);loading('output_div2','setTEXT','','<img src= ./loading.gif Uploading Image')"
    This forms a function called by the onsubmit event, and executing a return statement always terminates a function, regardless of its position.
    Tab-indentation is a crime against humanity.


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
  •