js: forms, input jbwyatt.com

An input form with a textbox and button: enter some text with multiple "x"s


Check me out!

<form class="cen"> <input type="checkbox" id="cb" />Check me out! <input type="text" id="stuff" /> <input type="button" onClick="All()" value="Call the function, All( )" /> </form>

// ez way to get id - like jquery function $(id) { return document.getElementById(id); } function All() { //get checkbox value var o = $('cb'); if ( o.checked == true ) alert("Checked"); else alert("Not Checked"); // get textbox info and report value in textbox and length var text = $('stuff'); alert("Value of text in input box: " + text.value); alert("Length of text in input box: " + text.value.length); // see if value in textbox is a number or not if( isNaN(text.value) ) alert( text.value + " is NOT a number."); else alert( text.value + " IS a number."); // see if textbox value is all alpha using a regular expression var alphaExp = /^[a-zA-Z]+$/; if(! (text.value.match(alphaExp)) ) { alert("Non-alphabetic text in input box: " + text.value); } // find x in text var start = 0; var loc = text.value.indexOf('x' , start); alert("The first 'x' is at index: " + loc + " in the textbox"); // find ALL the other xs start = loc + 1; loc = text.value.indexOf('x' , start); while( loc != -1) { alert("The next x is at: " + loc); start = loc + 1; loc = text.value.indexOf('x', start); } // get elements by TAG in a loop // get all the divs - returned in an array var j, i=0; do { j = document.getElementsByTagName('div')[i].innerHTML; alert("DIV" + i + ": " + j); i++; } while (j!= null); }