开发者

Passing PHP variable to Javascript dynammically added textbox

i have a javascript function like this:

function addfamily(divName){
    var newdiv = document.createElement('div');
    newdiv.innerHTML = '<input type="text" name="family[]" size="16">';
    document.getElementById(divName).appendChild(newdiv);
}

which dynamically adds textbox to the form and a php script like this:

<?php
$result_family = mysql_query("SELECT * FROM family_member where login_id='$_SES开发者_开发百科SION[id]'");

$num_rows_family = mysql_num_rows($result_family);

if ($num_rows_family>0) {

   while($row_family = mysql_fetch_assoc($result_family)){

   echo "<script language=javascript>addfamily('family');</script>";
   }
}

having this code the textboxes are added fine. i just need to know how can i set a dynamic value as the textbox value by passing the php variable $row_family[name] to the function and the value of the textbox??? please help


Since you want to pass the name of the Div along with $row_family['name'] your javascript function should look like

function addfamily(divName,familyName){
  var newdiv = document.createElement('div');
  newdiv.innerHTML = "<input type='text' name='family[]' size='16' value=" + familyName + ">";
  document.getElementById(divName).appendChild(newdiv);
}

and then the call from PHP should be like

echo "addfamily('family',$row_family['name']);";

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜