Sridhar_Rao
In the zone
I have a form with a set of elements that repeat but with different names & ids. I use javascript validation on these elements. It is fine when I have only one set but when there are multiple sets, repeating the javascript code for each of them is a stupid idea. How can this be accomplished with a single instance of code being used for several sets of elements.
This is simple. Assume, I have the same form with additional elements like this:
This is a stripped down and altered version of the form. Actual form is more complex and more elements and subfunctions.
I have a vague idea about this being achieved by using "this" reference, any help?
Code:
<script language="javascript">
function disp(){
document.getElementById('t1').value = document.getElementById('s1').value;
}
</script>
Code:
<form name="abc">
<select name="s1" id="s1" onchange="disp();">
<option value="ABC">ABC</option>
<option value="CDE">CDE</option>
<option value="EFG">EFG</option>
</select>
<textarea readonly rows="2" cols="50" name="t1" id="t1"></textarea>
</form>
This is simple. Assume, I have the same form with additional elements like this:
Code:
<form name="abc">
<select name="s1" id="s1" onchange="disp();">
<option value="ABC">ABC</option>
<option value="CDE">CDE</option>
<option value="EFG">EFG</option>
</select>
<textarea readonly rows="2" cols="50" name="t1" id="t1"></textarea>
<select name="s2" id="s2" onchange="disp();">
<option value="ABC">ABC</option>
<option value="CDE">CDE</option>
<option value="EFG">EFG</option>
</select>
<textarea readonly rows="2" cols="50" name="t2" id="t2"></textarea>
<select name="s3" id="s3" onchange="disp();">
<option value="ABC">ABC</option>
<option value="CDE">CDE</option>
<option value="EFG">EFG</option>
</select>
<textarea readonly rows="2" cols="50" name="t3" id="t3"></textarea>
</form>
This is a stripped down and altered version of the form. Actual form is more complex and more elements and subfunctions.
I have a vague idea about this being achieved by using "this" reference, any help?