Jump to content

Trouble Passing Values to Function


df_glazer

Recommended Posts

I have a page with a div, <div id= PF_Text_Panel></>, containing text that describes an image, the image is in a separate div. Using CSS the text panel is on top of the image and covers about 1/3 of the image’s left side. A slide effect, handled by the function Slide (see code below), targets the PF_Text_Panel div. The function Slide is triggered by an onClick event allowing the user to slide the description to the left and reveal the entire image. I am trying to write some code that will, in a sense, disable the slide effect with an onclick event. Until I turn it back on with another onclick event. The function Slide contains an if statement. The if statement is used to determine if PF_Text_Panel is open or closed using the variable SldPnlState as a flag. If the variable SldPnlState ==1, then run Slide. The other part of this function, which actually slides the div is an instance of the Slide Effect, inserted using Dreamweaver CS4. The variable SldPnlState is set using the function setSldPnlState The function setSldPnlState, initiated by an onClick, passes a value to the variable SldPnlState, in this case it can be set to either 0 or 1 by separate onClick events. It seems like the function Slide always refers to the default value of the variable and not value I am trying to pass. If set to 1 sliding occurs and if I set it to zero no sliding, but at least I know the slide function is working. So… …to test if the variable SldPnlState is being passed from the onClick event to the variable I included the function printVar which writes the value of the variable SldPnlState to the screen which seems to work fine, You can demo the page at: http://dg-ad.com/Sli..._Parameter.html Could there be a problem with how I am declaring the variable SldPnlState or thr function setSldPnlState, perhaps there is some conflict between local and global variable. Attached is the code, if anyone has some suggestions I would sure appreciate hearing from you:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Develop Slide Panel Logic Parameter" content="text/html; charset=utf-8" /><title>Develop Slide Panel Logic Parameter</title><link href="G-Ad Main Style.css" rel="stylesheet" type="text/css" /><!--begin setup Spry Effects--><script src="SpryAssets/SpryEffects.js" type="text/javascript"></script><script language="javascript" type="text/javascript"><!--Begin pass variable from flagToggle parameter to SldPnlState variable includes printVar function to sent results to screen--><!--begin set flag using onclick event-->var SldPnlState = 1;function setSldPnlState(flagToggle){SldPnlState = flagToggle;}</script><!--end set flag using onclick event--><!--begin slide function onclick event--><script type="text/javascript">if(SldPnlState==1)function MM_effectSlide(targetElement, duration, from, to, toggle, transition, fps, horizontal){Spry.Effect.DoSlide(targetElement, {duration: 500, from: 0, to: 200, toggle: true, transition: 2, fps: 750, horizontal: true});}//--></script><!--begin slide function onclick even--><!--begin write variable to screen onclick event--><script type="text/javascript">function printVar(){document.getElementById('test_display').innerHTML = SldPnlState}</script><!--begin write variable to screen onclick event--></head><body id="wrapper">  <div style="padding-top:50px;">  <a href="#" onclick="setSldPnlState(1);">Set var SldPnlState to Flag Status Set Open (1)</a><br><br><br>  <a href="#" onclick="setSldPnlState(0);">Set var SldPnlState to Flag Status Set Closed (0)</a><br><br><br> 		<a href="#" onclick="printVar();">Print Flag Status to Screen</a><br><br><br>	    <div id="test_display" style="border:#9CC thick groove; width:50px; height:50px; margin:15px; text-align:center; font-size:36px;"></div>	  		<a href="#" onclick="MM_effectSlide('PF_Text_Panel');">Slide Panel</a><br><br>		</div><div id="PF_Text_Panel" style="border:#9C9 thick solid; height:250px; margin-top:25px;">  <div id="PF_Text" class="PF_Text">  </div></div></body></html>

Link to comment
Share on other sites

i think this is the problem:

if(SldPnlState==1)function MM_effectSlide(targetElement, duration, from, to, toggle, transition, fps, horizontal){Spry.Effect.DoSlide(targetElement, {duration: 500, from: 0, to: 200, toggle: true, transition: 2, fps: 750, horizontal: true});}

right now the if condition is outside the function, you probably need it inside:

function MM_effectSlide(targetElement, duration, from, to, toggle, transition, fps, horizontal){    if(SldPnlState==1) {        Spry.Effect.DoSlide(targetElement, {duration: 500, from: 0, to: 200, toggle: true, transition: 2, fps: 750, horizontal: true});    }}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...