javascript hidden feild setting help

They have: 461 posts

Joined: Jul 2003

trying to create one function that will take a form name/id and a feild name/id and value.
it then sets the hidden feild tot he value and submits the form.

this completely lack of names is for modularity.
and also because i will be duplicating it and making a modified version that takes several hidden feild/value combinations

what i have right onw is the first function located @ http://24.91.157.113/findyourdesire/zctest.js
and as you can see in the test script located @ http://24.91.157.113/findyourdesire/zdtest.php
it's clearly not working. what i'm wondering is how to get it working and why it's not, so i wont make the mistake again

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

They have: 461 posts

Joined: Jul 2003

ok. here's the function:

function selsub(form,hfld,hval){ // submit a form and set a hidden variable
  document.getElementById(hfld).value=hval;
  document.getElementById(form).submit();
  return true;
}
'
here's the simple page made to test it:
<html>
    <title>test page</title>
    <style type="text/css">
      <!--
      @import url(textStyle.css);
      @import url(zatest.css);
      -->
    </style>
    &lt;script src="zctest.js" type="text/javascript"&gt;
      <!--
      -->
    &lt;/script&gt;
  </head>
  <body>
<form action="/findyourdesire/zdtest.php" id="tst" name="tst"><input type="hidden" name="test" />
<br /><a href="#" onclick="selsub('tst','test','clicky clicky');">click here to submit</a>
<br /><a href="#" onclick="selsub('tst','test','you clicked the wrong one');">click here to submit</a>

</form>
  </body>
</html>
'as you can see it's quite simple i'm trying to get the hidden feild to be set so i'll seee it in the location bar. at that point i can make 3 pages become html 4.01 compliant that i can't keep compliant any other way

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

You're trying to use getElementById(hfld) for an object that doesn't have an id set?

They have: 461 posts

Joined: Jul 2003

gah! i think you might be right
unfortunately i'm so used to html 3.0 since that's what i first learned and then i really never used it until 4.01 that i'm still not used to ids...

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

heh, happens.

As an aside: getElementById is not the only valid selector. Sometimes others like document.forms[i].elements(index) might be more useful.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.