i have been trying to add javascipt in my php script to implement dynamic form filling but it seems not to work. the javascript code works well without the php script what could br wrong?
var alive1 = new Array("Yes","No");
var alive2 = new Array("");
var loss = new Array("");
var dead = new Array("");
function set_ycontact(){
var select_status= document.form1.status;
var select_ycontact= document.form1.ycontact;
var selected_status= select_status.options[select_status.selectedIndex].value;
select_ycontact.options.length=0;
if (selected_status == "alive1"){
for(var i=0; i < alive1.length; i++)
select_ycontact.options[select_ycontact.options.length] = new Option(alive1[i],alive1[i]);
}
if (selected_status == "alive2"){
for(var i=0; i < alive2.length; i++)
select_ycontact.options[select_ycontact.options.length] = new Option(alive2[i],alive2[i]);
}
if (selected_status == "loss"){
for(var i=0; i < loss.length; i++)
select_ycontact.options[select_ycontact.options.length] = new Option(loss[i],loss[i]);
}
if (selected_status == "dead"){
for(var i=0; i < dead.length; i++)
select_ycontact.options[select_ycontact.options.length] = new Option(dead[i],dead[i]);
}
}
the corresponding php script is :
<td width="21%" class="invisible">Patients Status </td>
<select name="status" id="status" tabindex="6" onChange="set_ycontact();">
<option value="" selected="selected">Select status</option>
<option value="alive1" <?php if ($status=='alive1') echo "selected" ?>>Alive and promised to come to clinic</option>
<option value="alive2" <?php if ($status=='alive2') echo "selected" ?>>Alive-drop outs</option>
<option value="loss" <?php if ($status=='loss') echo "selected" ?>>Loss to follow up</option>
<option value="dead" <?php if ($status=='dead') echo "selected" ?>>Dead</option>
</select></td>
<td width="18%" class="invisible">Agreed To Yearly Contact</td>
<td width="1%" class="invisible">:</td>
<td width="25%" class="invisible">
<select name="ycontact">
<option value="" selected="selected"></option>
</select></td>
thanks
julie