Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views42 pages

Css Chapter 3

Css notes

Uploaded by

aditidhotre2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
21 views42 pages

Css Chapter 3

Css notes

Uploaded by

aditidhotre2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
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 Codestin Search App

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 Codestin Search App ; 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) } Codestin Search App = "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 Codestin Search App



S/body > Tech-Neo publicatio” — (New Syil_ w.e f academic year 19-20) (D5-16A) > (MSBTE Form and Eve outeut r ick) pefore C . _ . r po ( saveScriet Bwarnpte x + | | oC . Di/TechNeo%20Publications/dynamicibi htm! | Engineering ‘Compute | mechanical Engineering Submit || Class | after Click) TD eveSerpt exemple * pee Ss © File | DyTechNeo%20Publications/dynamicibihtmt wed =] re) omit || Department Note: In above program. when we will click on the button class we will get classes list and when we will click on the button department we will get department list; here note that class and department button is same only label or name will be changed dynamically. 3.8 MANIPULATING FORM ELEMENTS * The HTML Document Object Model or DOM Form object is associated with the HTML element. * We can create and access a form element using the createElement() and getElementById() method of the document object. Create a Button In JavaScript There are three steps to create button programmatically in JavaScript: Step 1 : Create a button using document createElement To create a button in JavaScript, we must use the createElement function available by default in the document interface of our web page. . __ After ating button we need to set text on it. New 5) Yl. wef academic year 19-20) (D5-16A) [al rech-neo Publications ae ipting Language (MSBTE) _(Form and Event Handling) Pg Client Side NO (3.94 Syntax document. createBlement(“element”); element.innerTerxt = “text”: Example dooument.createElement(button'), button.innerText = ‘New Button’; > Step 2: Add an event listener on button © The next step is to create an event listener on our button. It will allow y, to detect when a user clicks on it. Whenever the "click" event ji; detected, the arrow function (second parameter) is invoked. Syntax element.addEventListener(“event_name”, () => { #/ Code executed % D: Example button.addEventListener(click’, () => te alert(‘New Button Created’); ds > Step 3: Add JavaScript button in HTML document © The last step is to add our button to the HTML body. Example Codestin Search App output (Before Click) DD Button Example rit ‘Si © File | D:/TechNeo%20Publications/button.ntmt (After Click) Chee | Deerdeasz07 steamed Tie rage aye | ew Button Coated Se i a » 3.9 INTRINSIC JAVASCRIPT FUNCTIONS, DIS AEENS ELEMENTS, READ ONLY ELEMENTS _ ee 1 %& 3.9.1 Intrinsic JavaScript Functions * An intrinsic function (or built-in function) is a function (subroutine) available for use in a given programming language whose ___!mplementation is handled specially by the compiler. (New Syll. w.e.f academic year 19-20) (D5-16A) [eI Tech-Neo Publications. ae CO Client Side Scripting Language (MSBTE) (Form and Event Handling) p, 9 ne ® — JavaScript provides intrinsic (or “built-in”) objects. They are th he Boolean, Date, Error, Function, Global, JSON, Math, Numb¢ © Attay =, Seed, . i) i RegExp, and String objects. Obie, * Each of these objects holds several built-in functions to perfor, 1 Obje related functionality. Function Description - | This function is intended to cee wha I value is a legal number or not. * ne | a | | isFinite This function is intended to find whethe; ._ I number is a finite legal number. ‘ | eee eerie | eval This function is intended to execute Javascrip, i source code. | eee This function is intended to converts object to | the corresponding number value. | string This function is intended to converts object to L the corresponding string value. parseInt This function is intended to converts string value to integer. parseFloat This function is intended to converts string value to floating point number. escape This function is intended to encode the string value into worldwide acceptable format. encodeURI This function is intended to encode URI. decodeURI This function is intended to decode URI. _| I encodeURIComponent | This function is intended to encode URI | component. r | URI decodeURIComponent | This function is intended to decode component. yl wet ec tions (New Syl. w.e.f academic year 19-20) (D5-16A) [el tech-Neo Publicat! > : at Side, scripting Langua, je (MSBTE) Form and Event Handling) Pg. no. (3-37 cle’ owing are some built-in functions Fo isNaNO jgNaNO method determines whether value of a variable is 4 legal number or not prample aocumment-write(isNan(0)): i false gocumentwrite(isNan(JavaSeript)); // rue 2 eval eval() is used to execute Javascript source code. « Itevaluates or executes the argument passed to it and generates output. Example eval{"var number=2:number=number+2;document.write(number)"); //4 3, Number() « Number() method takes an object as an argument and converts it to the corresponding number value. + Return Nan (Not a Number) if the object passed cannot be converted to a number Example ver objl =new String("123"); var obi2=new Boolean("false") var obj3=new Boolean(“true"); . var obj4=new Date); var obj5=new String("9191 9999", document.rite(Number(objl))s 1 128 document.write(Number(obj2)); // 0 document.write(Number(obj3)); A Socument.write(Number(obj4)); // 1842720050291 document, write(Number(obj6))s // NaN ( New Syll. wef academic year 19-20) (D5-16A) hh PY! Tech-Neo Publications Client Side Scripting Language (MSBTE) (Form and Event Handling) Pano Pg (ay ) 4. Stringd * — String() function converts the object argument passed to it toa y value. m Example docuittent.write(new Boolean(0)); // false dooument.write(new Boolean(1)); // true document.write(new Date(); // Tue Jan 05 2021 13:28:00 GMT +0539 §. parseInt() * parseInt() function takes string as a parameter and converts it to integer Example ‘Aocument.write(parselnt('45")): document. write(parseInt("85 days") 3 document.write(parselnt("this is 9"); //NaN | * An optional radix parameter can also be used to specify the number system to be used to parse the string argument. Example document. write(parseInt(“10”,16)); /16 6. parseFloat() © parseFloat() function takes a string as parameter and parses it to a floating point number. Example ¢ In JavaScript, sometimes we need to enable and disable input elemen's like buttons, textfield, radio button, checkbox, label etc. However, evel? time when we make a change we need to reload HTML page. ‘New Syil. we f academic year 19-20) (D5-16A) tI } sch-INeo Publication® Pe ae de scripting Language (MSBTE) Form and Event Handling) Pg. no. (3-39) cient Si An element can be disabled in HTML by setting the disable property to true and enabled again by disabled=false In JavaScript, we can disable some elements to restrict the action perform by user for some reason steps Register enable() and disable() function with buttons to enable and disable button field Use the getElementByld() to access the button field set the disabled field to true or false; if set it false, it behaves like read only. Example Codestin Search App

Enabling and aiaae Button field using J javaScript

id="name" value="CLICK ME">

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