What is it?
What is a text box and when is it used?
Last Name: <input type="text" size="40" name="lastname" value="Smith">
What is a radio button and when is it used?
<input type="radio" name = "gender"><b>Female</b> <input type="radio" name = "gender" checked><b>Male</b> <input type="radio" name = "gender"><b>Unknown</b>
What is a checkbox and when is it used?
<input type="checkbox" name="beer"><b>Beer</b> <input type="checkbox" name="wine"><b>Wine</b> <input type="checkbox" name="goodstuff"><b>Scotch</b>
Send the form's data to the server application specified in the form tag
<input type="submit" value="Submit This Form">
Reset the form to it's default state (erase user entries)
<input type="reset" value="Reset This Form">
<input type="button" name="doTax" value="Calculate Tax">
What is a select type and when is it used?
<select size="4" name = "veggies"> <option>Carrots</option> <option selected>Brussel Sprouts</option> <option>Shitake Mushrooms</option> <option>Tomatos</option> <option>Herbs</option> <option>Peppers</option> <option>Onions</option> </select>
Select can also replace radio buttons:
<select size="1" name = "veggies"> <option>Carrots</option> <option selected>Brussel Sprouts</option> <option>Shitake Mushrooms</option> <option>Shitake Mushrooms</option> <option>Tomatos</option> <option>Herbs</option> <option>Peppers</option> <option>Onions</option> </select>
What is a textarea and when is it used?
<textarea rows="10" cols="40" name="novella"> Default text here </textarea>
Getting information from forms and their elements with scriptable commands
<form name="quiz1"> What is the Unix command to delete a file: <input type="text" name="deletequestion"><br> What is the Unix command to create a new directory: <select name = "dirquestion"> <option>mknew</option> <option>mkdir</option> <option>rmdir</option> </select> Do you believe you're right? <input type="checkbox" name="yes">Yes <input type="checkbox" name="no">No Are you: <input type="radio" name="sex">Male <input type="radio" name="sex">Female </form>
The above form in html
//read the text box (all the same!) var the_input = document.quiz1.deletequestion.value; var the_input = document.forms[0].elements[0].value; var the_input = document.quiz1.elements[0].value; var the_input = document.forms[0].deletequestion.value; //set the text box (again, all the same!) document.quiz1.deletequestion.value="chmod"; document.forms[0].elements[0].value="chmod"; document.quiz1.elements[0].value="chmod"; document.forms[0].deletequestion.value="chmod"; //read a checkbox //for the 'Yes' if (document.forms[0].yes.checked==true) { //OR if (document.forms[0].elements[2].checked==true) { //for the 'No' if (document.forms[0].no.checked==true) { //OR if (document.forms[0].elements[3].checked==true) { //read a radio button if (document.quiz1.sex[0].checked==true) { //read a select option //this is checking if 'mkdir' was selected! if (document.forms[0].elements[1].options[1].selected==true) {
<form name="sample" id="sampleId"> <h2>Test Form</h2> Name:<input type="text" name="name" id="nameId" size="30" value="Type your name here"> </form>
Test Form