[Javascript] wrox code question

Josiah Gordon jgordon at directfile.com
Mon Jul 9 14:56:36 CDT 2001


Carl,

> why does the indicated number NOT change when the page is refreshed.

They are making a rather careless mistake. They are setting the value of an
input before it exists. This *sometimes* works, but really shouldn't.

They are using an in-line script so that they can render the question HTML
randomly when the page loads, but are setting the value of txtQNumber before
they have written the HTML that creates that input.

Instead, the value of the input should be set when the page loads (although,
there are several ways that the same thing can be accomplished):

<BODY onLoad="javascript:document.QuestionForm.txtQNumber.value =
questionNumber + 1">

Try putting that line in your code. Without any other changes, the page will
work fine.


--Josiah Gordon
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.264 / Virus Database: 136 - Release Date: 7/2/2001





More information about the Javascript mailing list