Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form elements

Status
Not open for further replies.

ChetN

Technical User
Feb 9, 2001
42
US
I am using a questionnaire software which sets the "name" as a number rather than a word. Eg. name="1" I have the vendor's permission to add javascript so that is not an issue here.

The problem is that I cannot use javascript to add some text to the value for the "input." I get an error message if I use document.theForm.1.value.

Example.To this element
<input type=button, value=&quot;A&quot; name=&quot;1&quot;> I want the value to print in the resulting e-mail message: &quot;A is incorrect.&quot;

Since this is group under the name &quot;1&quot; what happens if I use document.theForm[10].value, if this is not the element I am addressing in the group?

Any ideas?
 
if you cannot alter how the form fields are being named, then you can access them with index/array notation. the array of form elements is zero-based.

e.g. if <input type=button, value=&quot;A&quot; name=&quot;1&quot;> is the first form element of the first form on the document, you can access it as &quot;document.forms[0].elements[0];&quot;

=========================================================
if (!succeed) try();
-jeff
 
Thanks for the quick reply. Your answer does work. It does mean that I have to manually.

Do you know how to code the program to find out which element? For example I have a questionnaire with about a hundred different elements (mostly checkboxes and radio buttons). I would like the system to know which element so that it can attach (from a different array) some value or string of text automatically

To give you an idea of what I am doing. My questionnaire is actually a classroom quiz. When the student selects the answer to a multiple-choice question, I want the system to check their answer (example: A) and if it is incorrect, I want the system to grab &quot;Sorry, the answer is B&quot; from an array of &quot;correct answers.&quot; Obvously I do not know which answer from the group will be chosen. I may add or delete questions which will also affect the manual element count.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top