View Full Version : referencing inputs on a form

07-13-2003, 04:49 PM
OK, I am now nearly insane. I want to change the value of a hidden field and programmatically submit a form to an asp. I can get a pointer to the form, but I can't get to the input.

This is just a shortened version of the table.

<form id="tbltree" action="GetData.asp" method="Post">
<Div id="DBStruct" >
<table id="tblList">
<tr><td class="tblName" onClick="GetTable(this)">Inquiries</td></tr>
<input type="hidden" name="tblnam" value="me" />

The javascript looks like this

function GetTable(which){
var it=document.all.tbltree;
alert(it.tblnam.value); 'This alert displays tbltree

I swear I have tried every variation of getElementById, document.all, and a pointer in the form of AForm.AField.Value.

Hurry, before the straight jacket squad arrives. I'm nearly at the drooling stage macking grunting noises while typing and testing. W3Schools has purposely not given me any help. The w3C Site has purposely left out the information I need. My wife and daughter are looking at me strangley! I think they are mocking me. The computer is mocking me!

07-13-2003, 08:07 PM
First of all, lose your (apparent) VB script mentality of uppercasing properties - all JS properties are lowercase. 2nd, ditch the IE-only document.all syntax.
// reference (like a pointer) to the form
var f = document.forms['tbltree'];

// reference to input
var inp = f.elements['tblnam'];

// setting value of input
inp.value = "someNewValue";Of course - you can refactor this process into one step

document.forms['tbltree'].elements['tblnam'].value = "someNewValue";However, it is helpful to store a reference if you will need it more than once.