Maharashtra HSC IT Commerce study materials
Maharashtra HSC IT Commerce study resources

Maharashtra HSC IT Commerce: Advanced JavaScript

Maharashtra HSC IT Commerce · Work through your exam, one topic at a time.

All guide sections

Advanced JavaScript

Advanced JavaScript tests client-side programming: DOM access, events, functions, validation and built-in objects. Questions ask you to trace output, repair a broken handler, or write a short validation routine.

Core rules and concepts

  • JavaScript runs in the browser (client side); it can change the loaded page through the DOM.
  • document.getElementById('id') returns one element; getElementsByClassName and getElementsByTagName return collections, so index them, e.g. [0].
  • Events include onclick, onsubmit, onchange and onmouseover. A handler returning false cancels the default action, such as form submission.
  • Declare with let or const; var is function-scoped and older.
  • == compares after type coercion; === compares both value and type.
  • Useful built-ins: Math.round(), Math.random(), parseInt(), toUpperCase() and Array.length.

Worked example

A form has <input id='email'> and <form onsubmit='return check()'>. Write the check. function check(){ var e = document.getElementById('email').value; if(e === ''){ alert('Email required'); return false; } return true; } Reasoning: .value reads what the user typed; the strict comparison catches an empty string. Returning false stops submission, while true allows it. Without return check() in the attribute, the function's return value is discarded and the form submits anyway.

Traps that cost marks

  • Writing document.getElementById('email').innerHTML to read an input value.
  • Forgetting [0] after getElementsByClassName.
  • Using = instead of == or === inside a condition.
  • Placing the script in <head> and querying elements before they exist.
  • Expecting alert() to return the user's input; it returns nothing useful.