Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1335 How can I pass a set of questions (one at a time) to a document.form.field.value with every click on a form button?

You are here: irt.org | FAQ | JavaScript | Form | Q1335 [ previous next ]

Try:

<html>

<head>

<script language="JavaScript"><!--
var cnt=0;

var Qs = new Array(
  'Question 1?',
  'Question 2?',
  'Question 3?',
  'Question 4?',
  'Question 5?'
);

function next(theForm) {
   theForm.question.value=Qs[cnt];
   cnt++
   if (cnt >= Qs.length) cnt = 0;
}
//--></script>

</head>

<body onLoad="next(document.forms[0])">

<form onSubmit="return false">
<input type="text" name="question" value="">
<input type="button" value="next..." onClick="next(this.form)">
</form>

</body>
</html>

©2018 Martin Webb