CS174
Chris Pollett
Apr 17, 2017
<input type="button" name="turnItOn" />then it could be accessed with document.forms[0].elements[0].
<input type="button" id="turnItOn" name="turnItOn"/>
button = document.getElementById("turnItOn");
myForm = document.getElementById("bob"); numButtons = myForm.vehicles.length; // if we want to we could cycle over this array for values. for( i =0 ; i < numButtons; i++) { oneVehicle = myForm.vehicles[i]. // do something }
<input type = "button" id="b" name="b" onclick="alert('b tapped');" />
document.getElementByID("b").onclick = myNewHandler;
<input type="text" id="cost" onfocus="this.value=10; this.blur();" />
<form ... onsubmit="return checkSubmit()" >
phoneStar = document.getElementById("phoneStar"); phoneStar.style.display="inline";
Which of the following statements is true? (Don't consider newer than ES5)
myelement.addEventListener("change", myhandler, false).
<p style="position: absolute; left:100px; top: 200px">some text </p> <p style="position: relative; left:10px; top: -20px; width: 50">some other text </p>
function moveIt(id, newTop, newLeft) { myStyle = document.getElementById(id).style; myStyle.top = newTop + "px"; /* notice how CSS properties are properties of the style object*/ myStyle.left = newLeft + "px"; }
<div id="test" style="visibility: hidden">hi there</div> <input type="button" onclick='show("test")' /> <script type="text/javascript"> function show(id) { myStyle = document.getElementById(id).style; myStyle.visibility = "visible"; } </script>