| | |
dynamic form filling
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
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 12:18 pm. Reason: added bbcode to code
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
![]() |
Similar Threads
- updating multiple rows with one form (PHP)
- Fetching Form Values with ASP (ASP)
- Storing dynamic form values in Arrays for display & insert (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
| Thread Tools | Search this Thread |
.htaccess alexa apache api array beginner beneath binary broadband broken cakephp checkbox class cms code convert cron curl database date display dynamic echo email emptydisplayvalue encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert ip javascript joomla key keywords limit link login mail mail() memberships menu mlm multiple multipletables mysql mysql_real_escape_string network oop open passwords paypal pdf php provider query radio random redirect remote rss script search securephp server sessions smtp source space sql strip_tags syntax system table template tutorial update upload url user validator variable video voteup web youtube





