Menu

[Solved]Use Documentforms 0 Return First Form Element Found Document Assign Element Returned Var N Q37105616

Use document.forms[0] to return the first form element found in the document. Assign the element returned to a var named fo

please include comments

Use document.forms[0] to return the first ‘form’ element found in the document. Assign the element returned to a var named form. Use the property onsubmit to add a submit event handler to the form element. . Have the onsubmit event call a function named checkForm. . Create a function checkForm that is passed the parameter e . Inside the body of the function use form.username to get the ‘username’ text element and assign it to the variable uname. . Following the variable declaration, create an if statement that checks two conditions that would cause the username to be invalid o If the value entered in the uname text input has a length that is less than 8 characters long (use the uname variable to get the value.length). o If value entered in the uname text input contains any spaces “”) (use the uname variable to get the value. indexOf method) o Note: Use a single if statement that checks if either of these error conditions are true Inside the body of the if statement o Alert a meaningful error message to the user (e.g. Username is too short or contains spaces’). o Use the focus) method to return the cursor to the uname field o Finally, call the preventDefault method using the event variable e then end the if statement. Try sabhmiting the form to tst wlicher your validation wowrk-s1 HTML (Body) CSS form method-“GET action-“submit.html” fieldset font-family: Verdana, Geneva, sans-serif; font-size:0,Gren; background-color: #eef;} fieldset> <legend >Change Password</legend > klabel>Username: Kinput types”text” label f text-align: right; display: block; max-width: 380px; margin: 2px; h name- “username”x/labe> <label>Password: <input type- “password name-“pwd1”></label> JavaScript Output “use strict” Change Password Username: Password: Confirm Password: Submit Show transcribed image text Use document.forms[0] to return the first ‘form’ element found in the document. Assign the element returned to a var named form. Use the property onsubmit to add a submit event handler to the form element. . Have the onsubmit event call a function named checkForm. . Create a function checkForm that is passed the parameter e . Inside the body of the function use form.username to get the ‘username’ text element and assign it to the variable uname. . Following the variable declaration, create an if statement that checks two conditions that would cause the username to be invalid o If the value entered in the uname text input has a length that is less than 8 characters long (use the uname variable to get the value.length). o If value entered in the uname text input contains any spaces “”) (use the uname variable to get the value. indexOf method) o Note: Use a single if statement that checks if either of these error conditions are true Inside the body of the if statement o Alert a meaningful error message to the user (e.g. Username is too short or contains spaces’). o Use the focus) method to return the cursor to the uname field o Finally, call the preventDefault method using the event variable e then end the if statement. Try sabhmiting the form to tst wlicher your validation wowrk-s1 HTML (Body) CSS form method-“GET action-“submit.html” fieldset font-family: Verdana, Geneva, sans-serif; font-size:0,Gren; background-color: #eef;} fieldset> Change Password klabel>Username: Kinput types”text” label f text-align: right; display: block; max-width: 380px; margin: 2px; h name- “username”x/labe> Password: JavaScript Output “use strict” Change Password Username: Password: Confirm Password: Submit

Expert Answer


Answer to Use document.forms[0] to return the first ‘form’ element found in the document. Assign the element returned to a var nam… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *