JavaScript - Can break function assignment, but not fix

Discussion in 'Software' started by Mada_Milty, Dec 4, 2006.

  1. Mada_Milty

    Mada_Milty MajorGeek

    Good Day,

    I have the following javascript code in a webpage I'm making:

    Code:
    function zoomin(){
    	if (v_zlevel > 1) {
    		if (v_zlevel == 10) {
    			document.zout.onmouseover=zoutOver()
    			document.zout.onmouseout=zoutOut()
    			document.zout.src ="images/raisedout.bmp"
    		}
    		v_row = "row"+v_zlevel
    		document.getElementById(v_row).bgColor = "#666699"
    		v_zlevel -= 1
    		document.mappic.src = "images/cgl"+v_zlevel+".gif"
    		v_row = "row"+v_zlevel
    		document.getElementById(v_row).bgColor = "#FFFFFF"
    		if (v_zlevel == 1) {
    			document.zin.onmouseover=dummy_fun()
    			document.zin.onmouseout=dummy_fun()
    			document.zin.src ="images/pressedzoom.bmp"
    		}
    	}
    }
    function zoomout(){
    	if (v_zlevel < 10) {
    		if (v_zlevel == 1) {
    			document.zin.onmouseover=zinOver()
    			document.zin.onmouseout=zinOut()
    			document.zin.src ="images/raisedzoom.bmp"			
    		}
    		v_row = "row"+v_zlevel
    		document.getElementById(v_row).bgColor = "#666699"		
    		v_zlevel += 1
    		document.mappic.src = "images/cgl"+v_zlevel+".gif"
    		v_row = "row"+v_zlevel
    		document.getElementById(v_row).bgColor = "#FFFFFF"
    		if (v_zlevel == 10) {
    			document.zout.onmouseover=dummy_fun()
    			document.zout.onmouseout=dummy_fun()
    			document.zout.src ="images/pressedout.bmp"
    		}
    	}
    }
    Which is supposed to dynamically change functions assigned to two different elements on my page. ('zin' and 'zout'). By default, their functions (zoutOver, zoutOut, zinOver, zinOut) work fine. However, when I get to the point of CHANGING them, I have no problem BREAKING the assignment, but I cannot reassign them their original functions. I know that the conditions here are being met, because the image's source does change as I want it to.

    I'm sure this is something simple that I'm overlooking, so if someone notices anything or has any advice, please let me know!
     
  2. Mada_Milty

    Mada_Milty MajorGeek

    Scratch it - this functionality is apparently not implemented in some crappy browsers like INTERNET EXPLORER :mad:
     
  3. Kodo

    Kodo SNATCHSQUATCH

    you can't do this!!

    document.zout.onmouseover=zoutOver()
    document.zout.onmouseout=zoutOut()

    What you've done is to actually EXECUTE the function upon your attempt to assign the event. do this instead:

    document.zout.onmouseover=zoutOver;
    document.zout.onmouseout=zoutOut;

    Now you will have the function reference assinged to the event without executing the function. Anytime you want to assign a function reference, do not incude () at the end of the function name. When you prototype an object, you must follow this rule.
     
  4. Mada_Milty

    Mada_Milty MajorGeek

  5. Mada_Milty

    Mada_Milty MajorGeek

    Sweet! That did it! Thanks alot, Kodo! I knew it must be some small syntax error. I'll keep this in mind for future reference.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds