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
}
Creating a dynamic textbox on a form
Moderator: General Moderators
-
EducatedFool
- Forum Newbie
- Posts: 3
- Joined: Tue Aug 12, 2008 1:00 pm
Re: Creating a dynamic textbox on a form
something like this?
<?php
if($dryice) {
echo '<input type="text" name="dryiceweight" value="">';
}
?>
<?php
if($dryice) {
echo '<input type="text" name="dryiceweight" value="">';
}
?>
Re: Creating a dynamic textbox on a form
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.
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
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:
2. Add
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. (: = :).
3. Function showDryIce() should look 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>Code: Select all
onchange="javascript:showDryIce()"3. Function showDryIce() should look like this:
Code: Select all
function showDryIce() {
// Makes div "dry_ice" visible.
document.getElementById('dry_ice').style.display='inline';
}