jQuery not passing variable after .click -


so have simple jquery script running. has 2 buttons, 1 sends data, , 1 button needs set value of 1 of variables send in first one.

ok here script button 1 (called preview):

$('#execute').click(function() { $('#currentimage').remove();  $.ajax({    type: "post",    url: "effect.php",    data: { action: $("[name='action']:checked").val(), source: sourceimage, destination: destinationimage, variables: $('#variables').val() },    success: function(msg){      $('#workspace').html(msg);      $("#preview").attr("src", destinationimage+"?timestamp=" + new date().gettime());    }  }); }); 

what put effect image , works wonderfull. 1 of first lines of javascript contains "sourceimage" variable.

var sourceimage = '20101201161609.jpg'; 

that variable correctly passed script above. second button (called save state) makes sure ones feel happy effect of image save state of image, , continue effects on image. means source image needs changed, use following script for:

$('#save_state').click( function() { var sourceimage = '2010-12-02-35-20-preview.png'; $('#header').html(sourceimage); }); 

i left line $('#header').html(sourceimage); in check if indeed triggered, , was, line not neccesary, know sure action triggered.

however, ones again click on "preview" in changes value of variable sourceimage value started with, while needs keep new value.

hope there's can me.

by using var keyword declare local variable in function, separate global variable same name. remove var keyword access global variable:

$('#save_state').click( function() {   sourceimage = '2010-12-02-35-20-preview.png';   $('#header').html(sourceimage); }); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -