User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,913 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,721 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 969 | Replies: 1
Reply
Join Date: Jul 2007
Posts: 1
Reputation: joruo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joruo joruo is offline Offline
Newbie Poster

Help dynamic form filling

  #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 11:18 am. Reason: added bbcode to code
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: dynamic form filling

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 7:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC