Page 1 of 1

Creating a dynamic textbox on a form

Posted: Tue Aug 12, 2008 2:09 pm
by rpamballa
Hi,

I very php development, and I am developing an html form. I have field called "dry ice weight" which has to appear only when the user requires to enter.
I am writing a pseudo code for what I want, can someone suggest me how to code it php? Any help is greatly appreciated.

if(dryice== yes)
{
create the text box to take the dry ice weight;
}else{
do nothing
}

Re: Creating a dynamic textbox on a form

Posted: Tue Aug 12, 2008 2:12 pm
by EducatedFool
something like this?

<?php
if($dryice) {
echo '<input type="text" name="dryiceweight" value="">';
}
?>

Re: Creating a dynamic textbox on a form

Posted: Wed Aug 13, 2008 1:36 pm
by rpamballa
I have an html form where I have to include this textbox based on the selection made form the list consisting of options "yes" or "No" on the same form.

For instance if I select to yes from the list the text for dryice weight should appear else if I select No the box should not appear.

Re: Creating a dynamic textbox on a form

Posted: Wed Aug 13, 2008 4:28 pm
by pkbruker
If you wanna do it without reloading the form (which would be the best idea), you'll have to use Javascript, not PHP. What you can do is something like this:

1. Place the entire form field within a div tag, give the tag the id "dry_ice" and make it invisible. Like this:

Code: Select all

<div id="dry_ice" style="display: none;">Here goes the form field</div>
2. Add

Code: Select all

onchange="javascript&#058;showDryIce()"
Within the form field which should cause the form field which should trigger the dry ice field. If there are other conditions than simply "onchange", put these in the showDryIce() function. (&#058; = :).

3. Function showDryIce() should look like this:

Code: Select all

 
function showDryIce() {
  // Makes div "dry_ice" visible.
  document.getElementById('dry_ice').style.display='inline';
}