views:

66

answers:

1
$.post("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){
  //alert(data1);
  var count = data1;
  var pid = $("#patient_id").val();
  var rid;

  for( var i = 1 ; i <= count ; i++) {
    var link ='<img src="/diabetes/ropimages/thumbpicdisplay.php?pid=+pid+&rid=1" />';
    $("#content1").empty().html(link);
  }
});

I am trying to pass pid value in url ..but its taking directly as +pid+ as value ..how do i give it the value of pid.

And how do i print 3 images in a div? like the one in code

+2  A: 

You simply need to terminate the string after ?pid= and then use the concatenation operator (+) to "insert" the pid variable in the appropriate location:

'<img src="/diabetes/ropimages/thumbpicdisplay.php?pid=' + pid + '&rid=1" />'

As for attaching the 3 images to the div, you might have more luck doing the following:

var link = '';

for(var i = 1; i <= count; i++) {
   link += '<img src="...thumbpicdisplay.php?pid=' + pid + '&rid=1" />';
}

$("#content1").empty().html(link);
Daniel Vassallo
hey i wrote code like this... for 1st loop it works then it stops working can u just tell me where i am going wrong
pradeep
$.getJSON("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){ var i;var count = data1.count; var start = data1.start; var pid = $("#patient_id").val(); for(i = start ; i <= count ; i++){var link ='<a href="/diabetes/ropimages/origpicdisplay.php?pid='+pid+'alert(link);if(i > start){$("#content1").append(link);}else{$("#content1").empty().html(link);} }},"Json");
pradeep
@pradeep: What value of `count` are you getting?
Daniel Vassallo
i am getting start value as 6 and count as 3 .when i try to add those 2 like count = count+start; and print it ..it gives like 36 instead of 9 . i think its taken it as string ..how to solve this prob?
pradeep
you can use `parseInt(count) + parseInt(start)` to avoid that problem.
Daniel Vassallo