narjis Posted August 22, 2012 Share Posted August 22, 2012 Hi, I'm loading the div successfully but it is not showing the alert message on load. I want to set click event on the input field which is inside this div. Please somebody help me. :'( . Here's my code. <form method="post" id="frm"> <select id="opt"> <option value="1">Controlled</option> <option value="2">With Notification</option> <option value="3">Periodically</option> <option value="4">Simple</option> </select> </form> <div> </div> <script src="js/jquery.ui.core.js"></script> <script src="js/jquery.ui.widget.js"></script> <script src="js/jquery.ui.datepicker.js"></script> <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script> <script> $("select").change(function () { var str = ""; $("select option:selected").each(function () { str += $(this).val() ; }); $.post("option.php",{data:str}, function(data){ $("div").addClass('datepicker').html(data); //alert(data); } ); }); $('div.datepicker').load(function(){ $('.cal').click(function(){ alert('hello'); }); }); </script> and here is my php code which is responding <?php $val=$_POST['data']; switch($val){ case 1: echo "<input id='cal' type='text' value='$val'/>"; break; case 2: echo "<input id='cal' type='text' value='$val'/>"; break; default: echo $val; break; } Quote Link to comment https://forums.phpfreaks.com/topic/267401-alert-help/ Share on other sites More sharing options...
requinix Posted August 22, 2012 Share Posted August 22, 2012 I don't see anything in there with a class of "cal". If you meant an ID of "cal" then you need to use $("#cal") Quote Link to comment https://forums.phpfreaks.com/topic/267401-alert-help/#findComment-1371322 Share on other sites More sharing options...
narjis Posted August 22, 2012 Author Share Posted August 22, 2012 i've changed it to $('#cal').click(function(){ alert('hello'); }); but it is still not working. Actually the load event is not triggering $('.datepicker').load(function(){ /*$('.datepicker').datepicker({ inline: true });*/ //alert('hello'); $('#cal').click(function(){ alert('hello'); }); }); }); what shall I do. Quote Link to comment https://forums.phpfreaks.com/topic/267401-alert-help/#findComment-1371336 Share on other sites More sharing options...
Adam Posted August 22, 2012 Share Posted August 22, 2012 Why are you calling load() on a DIV element? Only the window object has a load event: $(window).load(function(){ Edit Although it's worth mentioning, there's no need to wait for the window to finish loading to do what you want. You may as well start binding as soon as the document is 'ready': $(document).ready(function(){ Quote Link to comment https://forums.phpfreaks.com/topic/267401-alert-help/#findComment-1371356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.