I'm using the following script which allows selections to be chosen without the user having to hit submit. However, I can't seem to integrate any hidden input fields for passing my variables along (my preferred method). I don't want to use GET (ie ?variable='var' etc) and sessions are proving inflexible. Any ideas?
PHP Code:
<script type="text/javascript">
function nav1()
{
var v = document.myform1.home.selectedIndex;
var url_add = document.myform1.home.options[v].value;
window.location.href = url_add;
}
</script>
One option may be to "POST" the form. This eliminates the GET url chain you're looking to avoid and prevents using SESSION stuff. Just set the target of the form to the URL you're looking to send to and "SUBMIT". Something like the following (untested) code should do the trick:
But it's not working. My form was diverting successfully to a selected page when using the following:
window.location.href = url_add;
... but of course, no hidden variables were being submitted. I guess because I'm was using Javascript to select the page, rather than submitting. I'm guessing if I can use submit() then I'd be using the form properly and my hidden variables would be submitted?
Dasher... I also, (using your solution which I don't fully understand):
<script type="text/javascript">
function nav1()
{
var v = document.myform1.home.selectedIndex;
var url_add = document.myform1.home.options[v].value;
document.forms['myform1'].action = url_add;
document.forms['myform1'].submit();
}
</script>
I've verified it works.
Target specifies the window/frame the form submits in.
Action specifies the page the form submits to.
Apologies for the previous lapse of concentration.
P.S. I would recommend implementing Dasher's observation...The php code is missing a closing ' after the ".php" part of each of your options in your form.
Last edited by speghettiCode; 10-14-2010 at 05:48 AM.
Bookmarks