how to change the text of a textarea when a dropdown list is selected. Here is my code…
<html>
<head>
<script type="text/javascript">
function fifa()
{
abc=document.forms[0].browsers.value;
if(abc=="");
document.form1.text1value="you selected A";
else if
document.form1.text1.value="you selected B";
else
document.form1.text1.value="you selected C";
}
</script>
</head>
<body>
<form name="form1">
Choose which browser you prefer:
<select id="browsers" onchange="fifa()">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<textarea name="text1">
</textarea>
</form>
</body>
</html>
-thannx in advance
-Miss Subanki
Here is a corrected version of your function:
Points of interest. First, use the
varkeyword to declare variables inside of your functions. This ensures that your local variables will remain visible only inside the function in which they are needed. For large JavaScript programs, this is indispensible. Otherwise, without thevarkeyword, your variables will have global scope, possibly overwriting earlier global variables.Second, you must learn and understand JavaScript syntax. Examine my code and yours.
Third, I am using the === operator to test for equality instead of the == operator. Both will give the same result in this piece of code, but the === operator does not enforce type coercion in JavaScript. Trust me that later down the line, this will come in useful. Study up on this issue if you are not familiar with it.