Interactive Forms

Why interactive forms?stuffinside thetag is showing up, tables may be
Forms are easy enough to create when they areyourproblem. To fix this, either don't use tables, or
simple, likesearch boxes. But what if you need themcreate anentire seperate table for the information
to be complex? Howabout changing the forms basedinside thetag. Here is the code:
on input by the viewer? Thisis where interactiveFlower Order Form
forms using Javascript and HTML canhelp. I'll use aSelect how many flowers you would like:
simple example on how interactive forms canbe
useful.Number of Flowers
The problem1
I am going to use a business project as an example2
to teachinteractive forms. Imagine that we are3
creating a orderingsystem for flowers. We would like4
the customer to be able toorder a bouquet of5
flowers. The customer can choose to haveanyChoose type of flower 1:
number of flowers in the bouqet from 1 to 6. ForRed
eachflower, the customer can choose a type ofWhite
flower, and thereare 3 different kinds of flowers.Yellow
Now imagine all theseoptions as a regular form. ThereChoose type of flower 2:
would be 18 options tochoose from, even if you onlyRed
wanted one flower! This wouldbe ugly! In this tutorialWhite
we will learn how we can show andhide formYellow
elements depending on the input by the customer.Choose type of flower 3:
Now let's get started!Red
Creating the interactive formWhite
-HTMLYellow
We are going to create a page where you can enterChoose type of flower 4:
theinformation for ordering flowers. We've decidedRed
on having adrop down menu to select the number ofWhite
flowers, and then forthe number selected, displayYellow
that number of options tochoose the type of flower.Choose type of flower 5:
We'll start by creating the HTMLforms. First we willRed
write the html code for the form.White
Yellow
Number of FlowersChoose type of flower 6:
1Red
2White
3Yellow
4We used css to hide thetags. The next step is to
5usejavascript to show and hide each of
6thecellsdepending on what is selected in the drop
This will create a menu.down menu. We willstart out by making a javascript
Next we need to create the form where thefunction, then I willexplain the code and link it up with
customer willchoose the type of flower they wouldthe drop down menu.
like. We will let themchoose between a red rose, aJavascript
white rose, and a yellow rose.We are going to create a function that will show and
I am going to use radio buttons for the selection.hidethecells. There are 3 things we need to pass
Here isthe code:onto thescript: the number of total options, the name
Redprefix for thetags, and the number of options(to end
Whitethe loop). Hereis the script that I wrote:
YellowAdd this code inside the section of your page. Now
For this tutorial, I assume you have a basicwehave one less step; to call the function from the
knowledge ofdrop downbox. Here is the code to do that:
HTML. All of these pages still need mandatory tags,ue,'divCo
but Ileft them out because of the size they would
take up. Noticehow I made all the options the sameNumber of Flowers
name. This is so theyare grouped together, and only1
one option can be choosen.2
This is what it will look like: 0 Red 0 White 0 Yellow3
Duplicate this code 6 times, for each of the flower.4
Butevery time you see "color1", change that to a5
different nameso they are all seperate. I will use6
"color1", "color2",What this does is when the value is change, it will
"color3", and so on.pass onthe value, the name prefix of thecells, and
Now we need to put all of this together into anthenumber ofcells. In the first part, make sure
orderingform. But we need to add something so thatthegetElementById('numflowers') matches the 'id'
the forms candisappear. We will addtags around eachattribute inthe
of the flowertype selection rows. Enter the followingChoose type of flower 1:
code around each ofthe groups of options. MakeRed
sure that for each one, youlabel the id tag forWhite
thedifferently. For example, thefirst group will startYellow
withwill start withChoose type of flower 2:
IMPORTANT. When we pass variables onto theRed
script, the onlything that should change between theWhite
name of thetagsshould be the number. This isYellow
because we will use a loop togo through all theChoose type of flower 3:
numbers. We will pass through the name ofthetagsRed
to the javascript script, and the script willadd theWhite
numbers.Yellow
Choose type of flower 1:Choose type of flower 4:
RedRed
Whitename="color1" value="yellow">YellowWhite
Now we have each option groups surrounded byYellow
atag.Choose type of flower 5:
This will allow us to change their visibilityRed
withjavascript. I have puttags around the options,White
andadded a submit button. Note: when addingtagsYellow
inside atable, make sure they are contained within aChoose type of flower 6:
cell.Red
Something likeWhite
< d>< r>Yellow
< able>will not work for the same reason that addingThats all! Have a great day!
text outsideof cells inside a table doesn't work. If the