HTML and CSS Reference
In-Depth Information
<option value="#FFFF00">
<option value="#008000">
<option value="#0000FF">
<option value="#4B0082">
<option value="#EE82EE">
Easy ways to work with form values in JavaScript
This is another feature you've already seen in action. When you're
dealing with forms in JavaScript, the value is always a string, even if it
represents a date or a number. Because JavaScript automatically con-
verts the types of any value involved in an expression, this can easily
lead to errors that are hard to spot.
This code looks similar to the code
you saw in the section “The <output>
element,” but it doesn't have the
results you might expect:
<label for="one">Number: </label>
<input type="number"
value="5" name="one">
<label for="two">Range: </label>
<input type="range" name="two"
min="0" max="10" value="3">
<label for="out">Output: </label>
<output id="out" for="one two"
onforminput="value =
one.value +
Can you spot the difference?
Compare the last two lines with the
code used earlier (on the right):
one.value +
one.valueAsNumber +
Search WWH ::

Custom Search