roger v
asked on
How to detect if a particular button or link was clicked with Javascript?
Hi Experts,
I have a coldfusion 9 form that has some ajax processing going on. I need to identify if the user has actually saved a change made on the page or clicked away from the page without saving a value. So I need to perform some action if the user clicks on a couple of links that take them away from the page without saving. How do I do this with jquery or javascript?
I have a coldfusion 9 form that has some ajax processing going on. I need to identify if the user has actually saved a change made on the page or clicked away from the page without saving a value. So I need to perform some action if the user clicks on a couple of links that take them away from the page without saving. How do I do this with jquery or javascript?
ASKER
@leakim:
I'm a lil confused. So I have a bunch of <a href>s that the user can click to move away from the page. So my function would be like so:
<script language="javascript">
$(document).ready(function (){
$('.moveAwayLnk').click(fu nction(){
$('#textboxthatwaschanged' ).function ();{
$('#textboxthatwaschanged' ).value = $('#hiddenNameVal').value;
};
});
});
</script>
As you can see in the script, I have a class of links called moveAwayLnk, and if any of those links are clicked, that means that the user is navigating away from the page and therefore perform a specific function. Does that look right? Also, do I need a specific jquery plugin to perform this or just the regular jquery minified file?
I'm a lil confused. So I have a bunch of <a href>s that the user can click to move away from the page. So my function would be like so:
<script language="javascript">
$(document).ready(function
$('.moveAwayLnk').click(fu
$('#textboxthatwaschanged'
$('#textboxthatwaschanged'
};
});
});
</script>
As you can see in the script, I have a class of links called moveAwayLnk, and if any of those links are clicked, that means that the user is navigating away from the page and therefore perform a specific function. Does that look right? Also, do I need a specific jquery plugin to perform this or just the regular jquery minified file?
a better syntax :
$(document).ready(function(){
$('.moveAwayLnk').click(function(){
$('#textboxthatwaschanged').value = $('#hiddenNameVal').value;
});
});
or :$(document).ready(function(){
$('.moveAwayLnk').click(function(){
doSomething();
});
});
function doSomething() {
$('#textboxthatwaschanged').value = $('#hiddenNameVal').value;
}
ooops...
$(document).ready(function(){
$('.moveAwayLnk').click(function(){
$('#textboxthatwaschanged').val( $('#hiddenNameVal').val() );
});
});
or : $(document).ready(function(){
$('.moveAwayLnk').click(function(){
doSomething();
});
});
function doSomething() {
$('#textboxthatwaschanged').val( $('#hiddenNameVal').val() );
}
ASKER
@Leakim:
Just one question: How do I do an ajax call with jquery? Currently I use cfajaxproxy and get a proxy js class for the cf component. Then I use an instance of this class in js and call the cfc function like so:
var changeName = function(tv,te){
var objAppInfo = new ObjApp();
objAppInfo.setCallbackHand ler(update Info);
objAppInfo.setErrorHandler (myErrorHa ndler2);
objAppInfo.funcUpdateName( tv,te); //this is the remote function in the cfc that I call
}
//my callback function
var updateInfo = function(res){
if(res==1){
//location.reload(true);
//alert('capturing json data structure..');
return true;
}
else{alert('Error Occurred in updating Name!');}
return false;
}
var myErrorHandler2 = function(statusCode, statusMsg){
alert('Status: ' + statusCode + ', ' + statusMsg);
return false;
}
To do the same thing with jquery, how do I modify this?
Just one question: How do I do an ajax call with jquery? Currently I use cfajaxproxy and get a proxy js class for the cf component. Then I use an instance of this class in js and call the cfc function like so:
var changeName = function(tv,te){
var objAppInfo = new ObjApp();
objAppInfo.setCallbackHand
objAppInfo.setErrorHandler
objAppInfo.funcUpdateName(
}
//my callback function
var updateInfo = function(res){
if(res==1){
//location.reload(true);
//alert('capturing json data structure..');
return true;
}
else{alert('Error Occurred in updating Name!');}
return false;
}
var myErrorHandler2 = function(statusCode, statusMsg){
alert('Status: ' + statusCode + ', ' + statusMsg);
return false;
}
To do the same thing with jquery, how do I modify this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks much. Will open another question on how to do this in jquery and ajax.
Open in new window
Open in new window