Chapter 7
If using the DOM Level 0 events, returning
falsefrom the event handler and the event-handler script cancels the submittal. If using DOM Level 2, setcancelBubbletotruefor IE, and call thepreventDefaultfor other browsers, both based on the event object.The blur event is triggered when the field loses focus. This is a good time to check the text field to make sure it has valid data.
The select options are stored in an array called
Options. As such, you can add new options as you would add new array elements, making sure that the entry is a newOptionobject:opts[opts.length] = new Option("Option Four", "Opt 4");Hereâs one approach:
var rgEx = /^[A-Za-z\s]*$/g; var OK = rgEx.exec(document.someForm.text1.value);
The code must first assign an event-handler function to each radio buttonâs
onclickevent handler:document.someForm.radiogroup[0].onclick=handleClick; document.someForm.radiogroup[1].onclick=handleClick;
If there are several buttons, this can be managed in a
forloop. In thehandleClickfunction, test the check status, and disable the form element accordingly. For instance, to disable the submit button:function handleClick(ââ) { if (document.someForm.radiogroup[1].checked) { document.someForm.submit.disabled=true; } else { document.someForm.submit.disabled=false; } }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access