Jump to content

alert() help


narjis

Recommended Posts

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;
}

 

Link to comment
https://forums.phpfreaks.com/topic/267401-alert-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/267401-alert-help/#findComment-1371336
Share on other sites

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(){

Link to comment
https://forums.phpfreaks.com/topic/267401-alert-help/#findComment-1371356
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.