...

View Full Version : referencing inputs on a form



ScottInTexas
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>
</table>
<input type="hidden" name="tblnam" value="me" />
</div>
</form>

The javascript looks like this


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


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!

beetle
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum