0% found this document useful (0 votes)
8 views

Css chapter 3

Css notes

Uploaded by

aditidhotre2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views

Css chapter 3

Css notes

Uploaded by

aditidhotre2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 42
Te ee ¢ Form and Event Handling CHAPTER 3 Syllabus | eee | 3.1 Building blocks of a Form, properties and methods of form, button, | | text, text area, checkbox, radio button, select element | 3.2 Form events — mouse event, key events | | 3.3 Form objects and elements | | 3.4 Changing attribute value dynamically 3.5 Changing option list dynamically 3.6 Evaluating checkbox selection 3.7 Changing a label dynamically 3.8 Manipulating form elements 3.9 Intrinsic JavaScript functions, disabling elements, read only elements. 1 3.1 BUILDING BLOCKS OF A FORM, PROPERTIES AND METHODS OF FORM, BUTTON, TEXT, TEXT AREA, CHECKBOX, RADIO BUTTON, SELECT ELEMENT % 3.1.1 Building Blocks of a Form Form object represents an HTML form. 4 (Form and Event Handling) Pano (3, ing Lange © The
tag is used to add HTML forms to the web page for \,,, input. Forms are used to pass the data submitted by the user tc, the server © It is used to collect user input through elements like text fields, che, box and radio button, select option, text area, submit buttons and etc Syntax ..
The Element * The HTML element is the most used form element. * An element can be displayed in many ways, depending on the type attribute. | ‘Type ae Description Displays a single-line text input field Displays a radio button (for selecting one of many choices) +t | Displays a checkbox (for selecting zero or | i more of many choices) Displays a submit button (for submitting the form) — — Displays a clickable button The
element contains other HTML tags, which define the inp! method of data |. The

function myFunction() { varx = document.getElementByld("myTextarea").value; “ooument getElementB yld("demo").innerHTML = x; 7 Slit > \New Syl. wef academic year 19-20) (D5-16A) UB rech-nveo Publications —_—e | ng Language (MSBTE) (Form and Event Handling) Pg. no, a Output i Fa Cy tereres Extn x oe I | ~ eo DyTechNeo%z0Pub Jications/textarea htm} € \ | Address | [examinareyan Temede, iis Click Ma | | Syanmmarayan Temple, Pune | toeeeee e — Check box object represents a checkbox in an HTML form. © It allows the user to select one or more options from the availabj, choices. Syntax Properties Property 2 Deseription a Name | It sets or returns the name of the checkbox. | | Type Tt returns the value “check”. | Value Tt sets or returns the value of the attribute of a checkbox. | | Checked It sets or returns the checked state of a checkbox. | defaultChecked | It returns the default value of the checked attribute. Methods Method _ click() It sets the checked property. Example Checkbox Example

Click the button to create a Checkbox

(New Syll. w.e f academic year 19-20) (D5-16A) [al tech-Neo Publicatio™ rn eee a a a eee Reh eet client Side Scripting Language (MSBTE) (Form and Event Handling) Pg. 10. (3-13) fanetion myFunc ction?) { ap 2 = dooument-c reateElement("input’); saaateibae "type", “checkbox"); checked = true; document body.appendChild(x); } Output TD Checkbox Example x + G Ofte | Click the button to create a Checkbox D:/TechNeo%20Publications/checkbox1.htm! aaa % 3.1.7 Radio Button Object 1 1 GQ Write the * Radio object represents a radio button in an HTML form. * — It allows the user to select only one option from the available choices. Syntax . Properties ert 4 Description Property : P' "Checked It sets or returns the checked state of a radio button, defautChecked It returns the default value of the checked attribute. Name It sets or returns the value of the name attribute of a radio button. | Type 1 Ireturns | the type of element, whi al radio button. 4 ts or returns the value of the radio button i ‘€w Syll. wef academic year 19-20) (D5-16A) [el rech-teo Publications, “ Client Side Scripting Language (MSBTE) (Form and Event Handling) Pg. ne, 0 ee ee ae aneneannentatieta 14 present only vegetable names to the user. Methods Method * Daberlpeion | blur ) | It takes the focus away from the radio button. le click) + Tt acts as if the user clicked the button. | focus() _ [te gives the focus to the radio button. Example tates eae al caesar ae Sis EE ' UQ. Write a HTML script, which displays two radio buttons to the user, ' ' for fruits and vegetables and one option list. When user select fruits | : radio button option list should present only fruits names to the use, ; ‘ & when user select vegetable radio button Peso list shouig | 1 ' 1 with(document.forms.myfoi L) if(ElementValue = { ‘ optionList{O].text="Mango"; optionList{O).value=1;- 0” optionList[] ].text= "Banana"; optionList{1].valu optionList(2] text= option| ist[2].value=3: : (New Syll. w.e.f academic year 19-20) (D5-16A) Tech-Neo Publication> Form and Event Handling) Pg. no. (3-15) Client Side Scripting Language (MSBTE) ( jf(ElementValue == 2) { optionList{0}.text="Potato’s optionLi at{O].valie= ly aptionLiat[1].text="Cabbage’s optionList[1} value= Ss aptionList{2].text="Onion’: optionList{2].value=3; yt © — (New Syl. w.e.f academic year 19-20) (D5-16A) & Tech-Neo Publications. a. \ Fruits ® Vegetables i Reset WW 3.1.8 Select Element and Option Element Vee Ow ee SOR ee * Select object represents a dropdown list in an HTML form. * A dropdown list is a toggleable menu that allows the user to choose one option from multiple ones. Add the multiple attribute to the element, which reflects the index of the selected option value=" Mango" > Mango 3 Banana" > Banana Output (Before Select) [ exeane oe OB cption3.htmni x G © Fite | DytechNeo%20Publications/option3,html List of Frit: (gple ——¥) [ Sea] (After Select) @ DB option’s.htmt Co © Fite | D:/TechNeo%20Publications/option3.html Your Favorite Fruit is Apple. 4 3.2 FORM EVENTS - MOUSE EVENT, KEY EVENTS C2502 ee meen 1 GQ. What is an Event? : ' SQ. Enlist different type of mouse events, ! B Enlist different type of keyboard events. The Change in the state of an object is known as an Event. ‘New 5 Il. wef academic year 19-20) (D5-16A) Blrech-neo Publications. “~ > y JavaScript Mouse Events ; u |
< form> f function click event() { alert("This is a JavaScript Mouse Event"); SIseript> “html > (Ne &W Syll. wef academic year 19-20) (D5-16A) fl Tech-Neo Publications. ~~ Client Side Scripting Language (MSBTE Form and Event Handling) Po. a, ——— Output (Before Click) fee Om Mouse Events x + =. | G ©) File | DyTechNeo%20Publications/mouse hyn, ie ‘ | | Ok Me | | | | —_| (After Click) BD waceretecntere, xr omen | ise -Thepage ra | | thet ama ose os Bt %® 3.2.2 Keyboard Events The keyboard events that are invoke by keyboard. | Event Performed | Event Handler Description | | Keydown & Keyup | onkeydown & onkeyup | When the user press and then release the key ie Example (onkeydown) } JavaScript Keyboard Events = "blue"; Output (Before Click) Oo [B seveScript Example x + G © Fie | Dy/TechNeo%20Publications/style-htm! Welcome to JavaScript Programming ‘Click on the button to change the style attribute Lissa) Tech-Neo Publication (New Syll. w.e.f academic year 19-20) (D5-16A) ge seupti Language (MSBTE) (Form and Evant Handling) Pg_no. (3-27 ie | ewe | | seyte attribute Changed “jp above program. select the element whose style properties need to be change and use element.style property fo set the style attribute of an element. note: — w 35 CHANGING OPTION LIST DYNAMICALLY « In JavaScript, we can change the option list of pull down menu dynamically at the run time according to the user choice. + We can add new options in the existing list or remove the options already added. Steps Create the HTML element. Write function and call it on any events. Example Dropdown List Example seript> n addOption(){ = document.getElementByld("dynamic-select’); “ptions{select.options.Jength] = new Option(‘New Element’, '0’); emoveOption() { ect = + document.getElementByld(“dynamic-select"); “Honslselect options length - 1) = null Sy . w" wef academic year 19-20) (D5-16A) la) rech-neo Publications. a Client Side Seriptin, Language (MSBTE) (Form and Event Handling) Py. ng a a (3 } i function removeAll Options(){ var select = document.getElementByld(dynamic-select"); select.options.length = 0: } Editable Textfield Output (Read Only Text field) HD JavaScript Example x CG © Fite | D:/TechNeo%20Publications/textfield1.htmt Make text field read only using JavaScript Eater your name: } [ReadOnly Texted | Editable Texted | Tech-Neo Publications ‘N = Syll. wef academic year 19-20) (D5-16A) “ae

You might also like