944,122 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2589
  • PHP RSS
Jul 15th, 2007
0

dynamic form filling

Expand Post »
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?
javascript Syntax (Toggle Plain Text)
  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 :
php Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
joruo is offline Offline
1 posts
since Jul 2007
Jul 15th, 2007
0

Re: dynamic form filling

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
Reputation Points: 33
Solved Threads: 7
Junior Poster in Training
johny_d is offline Offline
92 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP on a Standalone PC
Next Thread in PHP Forum Timeline: mysql_real_escape_string woes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC