I have 3 files:
- js_json.js -> for my json code
- javascript.js -> for my javascript function
- index.php
Here is the code for js_json.js
:
$(function(){ $('#postTitle').change(function(){ var title_id = $("#postTitle").val(); $.ajax({ type:"post", url:"proses.php", data:"title_id=" + title_id, dataType:"json", success:function(data){ body=""; //$.each(data, function(i,n){ //body = n['body']; //}); body += "<a href=\"javascript:void(0);\" id=\"pesan\" name="pesan" onClick=\"\">Hola Test</a>"; $(".postBody").empty(); $(".postBody").append(body); }, error:function(data){ $(".postBody").empty(); $(".postBody").append("NO Post Selected."); } }); return false; }); });
and here is my javascript.js
code:
$(function (){ $("a[name=pesan]").click(function (){ alert("holalalalalal.....!"); }); });
and here is the index.php
code:
//some code <body> <a href="javascript:void(0);" id="pesan" name="pesan">Hola Test 1</a> Posts : <br /> <select name="title" id="postTitle"> <option value="">Select Post...</option> <?php $sql = "SELECT id, title FROM posts ORDER BY title"; $query = mysql_query($sql) or die(mysql_error()); while($rows = mysql_fetch_array($query)){ print('<option value="' . $rows['id'] . '">' . $rows['title'] . '</option>'); } ?> </select> <br /> Body : <br /> <div class="postBody"> Will show the body of post. </div> </body> </html>
and my question is:
When I click the "Hola Test 1" link, it works and a message appears. The problem is that after I click the "Select" button and the "Hola Test" link appears, and then I click the link ("Hola Test"), the message will not appear and there are no errors in firebug ...
Can someone explain to me why ...? Thanks this ...
Sindhu13
source share