javascript hidden feild setting help
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.
m3rajk posted this at 01:53 — 27th April 2004.
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>
<script src="zctest.js" type="text/javascript">
<!--
-->
</script>
</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>
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Abhishek Reddy posted this at 06:02 — 27th April 2004.
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?
m3rajk posted this at 23:48 — 27th April 2004.
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 posted this at 03:58 — 28th April 2004.
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.