Hi Below I have piece of code where it displays a message stored in another php page using jquery and a html div tag known as 'targetdiv:
function submitform() {
$.ajax({
type: "POST",
url: "updatestudentsession.php",
data: {
Idcurrent: $('#currentid').val(),
addtextarea: $('#studentadd').val()
},
dataType:'json', //get response as json
success: function(result){
if(result.errorflag){
//do your stuff on getting error message
var newHtml="<span style='color: red'>"+result.msg+"</span>";
$("#targetdiv").html(newHtml); //i am displaying the error msg here
}else{
//you got success message
var newHtml="<span style='color: green'>"+result.msg+"</span>";
$("#targetdiv").html(newHtml);
$('#targetdiv').show();
}
}
});
}
Now what I am trying to do is that if the user has selected from a drop down menu after that message has appeared, I want it to hide the message. The problem is that when I try to do this, the message does not appear even if I submit the form it does not show the message. My question is how am I suppose to hide the message in the #targetdiv tag when option changes but still be able to show the message after the user has submitted the form?
Below is what I tried to do:
$(document).ready( function(){
$('#sessionsDrop').change( function(){
$('#targetdiv').hide();
var search_val = $(this).val();
});
});
1 Answer