•
•
•
•
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
![]() |
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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?
the corresponding php script is :
thanks
julie
javascript Syntax (Toggle Plain Text)
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 :
php Syntax (Toggle Plain Text)
<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
Last edited by stymiee : Jul 15th, 2007 at 11:18 am. Reason: added bbcode to code
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
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
$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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Fetching Form Values with ASP (ASP)
- Storing dynamic form values in Arrays for display & insert (PHP)
- updating multiple rows with one form (PHP)
- Need help in design and javascript code for Dynamic form (JavaScript / DHTML / AJAX)
- using variable for dynamic from elements (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: PHP on a Standalone PC
- Next Thread: mysql_real_escape_string woes


Linear Mode