dynamic form filling

Reply

Join Date: Jul 2007
Posts: 1
Reputation: joruo is an unknown quantity at this point 
Solved Threads: 0
joruo joruo is offline Offline
Newbie Poster

dynamic form filling

 
0
  #1
Jul 15th, 2007
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?
  1. var alive1 = new Array("Yes","No");
  2. var alive2 = new Array("");
  3. var loss = new Array("");
  4. var dead = new Array("");
  5. function set_ycontact(){
  6. var select_status= document.form1.status;
  7. var select_ycontact= document.form1.ycontact;
  8. var selected_status= select_status.options[select_status.selectedIndex].value;
  9. select_ycontact.options.length=0;
  10. if (selected_status == "alive1"){
  11. for(var i=0; i < alive1.length; i++)
  12. select_ycontact.options[select_ycontact.options.length] = new Option(alive1[i],alive1[i]);
  13. }
  14. if (selected_status == "alive2"){
  15. for(var i=0; i < alive2.length; i++)
  16. select_ycontact.options[select_ycontact.options.length] = new Option(alive2[i],alive2[i]);
  17. }
  18. if (selected_status == "loss"){
  19. for(var i=0; i < loss.length; i++)
  20. select_ycontact.options[select_ycontact.options.length] = new Option(loss[i],loss[i]);
  21. }
  22. if (selected_status == "dead"){
  23. for(var i=0; i < dead.length; i++)
  24. select_ycontact.options[select_ycontact.options.length] = new Option(dead[i],dead[i]);
  25. }
  26. }

the corresponding php script is :
  1. <td width="21%" class="invisible">Patients Status </td>
  2.  
  3. <select name="status" id="status" tabindex="6" onChange="set_ycontact();">
  4. <option value="" selected="selected">Select status</option>
  5.  
  6. <option value="alive1" <?php if ($status=='alive1') echo "selected" ?>>Alive&nbsp;and&nbsp;promised&nbsp;to&nbsp;come&nbsp;to&nbsp;clinic</option>
  7. <option value="alive2" <?php if ($status=='alive2') echo "selected" ?>>Alive-drop&nbsp;outs</option>
  8. <option value="loss" <?php if ($status=='loss') echo "selected" ?>>Loss&nbsp;to&nbsp;follow&nbsp;up</option>
  9. <option value="dead" <?php if ($status=='dead') echo "selected" ?>>Dead</option>
  10. </select></td>
  11. <td width="18%" class="invisible">Agreed&nbsp;To&nbsp;Yearly&nbsp;Contact</td>
  12. <td width="1%" class="invisible">:</td>
  13. <td width="25%" class="invisible">
  14.  
  15. <select name="ycontact">
  16. <option value="" selected="selected"></option>
  17. </select></td>

thanks
julie
Last edited by stymiee; Jul 15th, 2007 at 12:18 pm. Reason: added bbcode to code
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 68
Reputation: johny_d is an unknown quantity at this point 
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: dynamic form filling

 
0
  #2
Jul 15th, 2007
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:
<body onLoad="set_ycontact();">
so you trigger the form fields update on page load.

That's all
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC