tags:

views:

57

answers:

1

hello

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='$_SESSION[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 theb value of the textbox??? please help

+1  A: 

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

Anand
wow,thank you very muchhhhhhh,god bless you!you really helped me alot
adi
@adi - If this answer solved your problem, click the Accept Answer checkbox to the left of the answer.
Jeremy Stein