Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Thanked 4 Times in 4 Posts

    referencing inputs on a form

    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!
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Thanked 0 Times in 0 Posts
    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.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts