We can use validation for some fields such as:
- to check whether required field is empty ?
- to check whether user has entered valid email address.
- to check whether user has entered valid date.
- to check whether user has entered text in numeric filed.
- var debug = document.forms[“myform”][“fname”].value this line creates variable which has equal value of fname value.
- if (debug == null || debug == “”) line contains OR sign which indicates if value is null or empty display the alert message and if input field is empty it returns false.
- <input type=”button” onclick=”validate();” value=”submit” /> tag contains submit event when user clicks the submit button and onclick() event occurs when a button is clicked.
Once script has been loaded into debugger, it can be run one line at a time or it can be stopped at certain break points. . If no debugging statement is available then consider the statement has no effect. Once execution is halted, the programmer can examine the state of the script to determine if something is amiss.
There are some debugging steps as follows:
- Recognize the bug if it exists in the program. It can be done passively. If program detects serious problem, bug can be recognized and error message will be displayed on the screen.
- Identify the portion which is causing the error. It involves iterative testing process. By testing input and output iteratively, the programmer can identify where the error is occurring.
- Determine cause of the bug which may involve other portions of the program. Sometimes error may be external to the system. Error may occur due to unexpected values, logic error or unexpected values in different fields etc.
- After identifying the problem, determine how to solve the problem.</li.
- After fixing the problem, it is important to test the program and determine program is running correctly.
- Open browser, press ctrl+shift+J to open developer tools or press F12 button to open developer tools.
- In another way you can also open developer tools i.e. On the web browser ,select Customize and Control Google Chrome with 3 horizontal lines to the right side of the address bar. Click on Tools, the select Developer Tools.
The following image will show developer tools in Google Chrome:
- You can add breakpoints and watch statements etc. Click the Start Debugging with your script and it should highlight the statement it reaches before erroring.
The following image will show developer tools in Internet Explorer :
- Open the browser, click on Tools, select Web Developer -> select Debugger.
- You can also select Debugger by using shortcut key Ctrl+Shift+S from the keyboard.
The following image will show developer tools in Mozilla Firefox: