Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1670 Can you change the values of form fields when a checkbox is clicked?

irt.org | Knowledge Base | JavaScript | Form | Q1670 [ previous next ]

Q1670 Can you change the values of form fields when a checkbox is clicked?

Try:

<html>
<head>

<script lannguage="JavaScript"><!--
function fillIt(type,theForm) {
  if (type == 1) {
    theForm.elements['fieldA'].value = 'Now is';
    theForm.elements['fieldB'].value = 'the time';
    theForm.elements['fieldC'].value = 'for all';
    theForm.elements['fieldD'].value = 'good men';
  }
  else if (type == 2) {
    theForm.fieldA.value = 'to come';
    theForm.fieldB.value = 'to the';
    theForm.fieldC.value = 'aid of';
    theForm.fieldD.value = 'their country';
  }
}
//--></script>

</head>

<body>
<form>
<br><input name="fieldA" type="text" value="initial value">
<br><input name="fieldB" type="text" value="initial value">
<br><input name="fieldC" type="text" value="initial value">
<br><input name="fieldD" type="text" value="initial value">
<br>Part1:
<input type="checkbox" onClick="if (this.checked) fillIt(1,this.form)">
<b>Part2:
<input type="checkbox" onClick="if (this.checked) fillIt(2,this.form)">
</form>

</body>

</html>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.