php - Why can't I access textarea id's after parsing array -


i'm loading multiple clients on page, each record own <textarea>. set each <textarea> client's clientid.

if(isset($_post['loaddata'])){     try{         $stmt = $db->prepare('select clientid, fname, lname                             clients                             memberid = :memberid                               , groupid = :groupid                             order lname');         $stmt->bindvalue(':memberid', $_session["memberid"], pdo::param_int);         $stmt->bindvalue(':groupid', $_post['groupid'], pdo::param_int);         $stmt->execute();         $result = $stmt->fetchall();         foreach($result $row ) { $i++;          echo '<tr style="'.getbgc($i).'">                 <td style="display:none">'.$row[0].'</td>                 <td style="width:auto;">'.$row[1].'</td>                 <td style="width:auto;">'.$row[2].'</td>                 <td><textarea id='.$row[0].' class="form-control" rows="1"></textarea></td>             </tr>';         }     } ... 

after data loads, test <textarea> id's:

$.ajax({         url     : 'wsparticipation.php',         type    : 'post',         async   : false,         data    : {                     'loaddata'  : 1,                     'groupid'   : temp         },         success:function(re){             $('#showdata').html(re);             $('#13').html("i 13");             $('#15').html("i 15");             $('#10').html("i 10");         } ... 

and textareas show html.

when ready save the entered data, set clientid's array.

if(isset($_post['getarray'])){     $stmt = $db->prepare('select clientid                             clients                             memberid = :memberid                               , groupid = :groupid                             order lname');     $stmt->bindvalue(':memberid', $_session["memberid"], pdo::param_int);     $stmt->bindvalue(':groupid', $_post['groupid'], pdo::param_int);     $stmt->execute();     $result = $stmt->fetchall();     $ret = array();     foreach($result $row ) {         $ret[] = $row['clientid'];     }     echo json_encode($ret);     exit(); }  $.ajax({         url         : 'wsparticipation.php',         type        : 'post',         datatype    : 'json',         data        : {                     'getarray'  : 1,                     'groupid'   : temp         },         success:function(re){             data = $.parsejson(re);             $.each(data, function(i, clientid) {                 alert(clientid);                 $('#clientid').html("hahaha");             });             $('#2').html("made here this");         } }); 

the alert() indeed shows me each of clientid's, next statement $('#clientid').html("hahaha"); nothing. last statement $('#2').html("made here this"); puts text in appropriate textarea.

so, since alerts showing me clientid's, why not able access textarea using clientid $.each(data, function(i, clientid)?

$('#clientid') selects element id of "clientid".

i think want dynamically build selector concatenating "#" symbol variable's value:

 $('#'+clientid).html("hahaha"); 

example below:

var clientid = 2;  $('#' + clientid).html('test');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <textarea id="2"></textarea>


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -