954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

dynamic form filling

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&nbsp;and&nbsp;promised&nbsp;to&nbsp;come&nbsp;to&nbsp;clinic</option>
			  <option value="alive2" <?php  if ($status=='alive2') echo "selected" ?>>Alive-drop&nbsp;outs</option>
			  <option value="loss" <?php  if ($status=='loss') echo "selected" ?>>Loss&nbsp;to&nbsp;follow&nbsp;up</option>
			  <option value="dead" <?php  if ($status=='dead') echo "selected" ?>>Dead</option>
			</select></td>
            <td width="18%" class="invisible">Agreed&nbsp;To&nbsp;Yearly&nbsp;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

joruo
Newbie Poster
1 post since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

First, if you have Register Globals = Off in your php.ini (which is recommended), than you have to extract your $status variable from your post data, with a line like:
$status = $_POST['status']; (or $_GET['status'], if your form uses the Get method)
Second, change the Body tag of your html to:

so you trigger the form fields update on page load.

That's all ;)

johny_d
Junior Poster in Training
94 posts since May 2007
Reputation Points: 33
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You