I have a small form, with a single dropdown - it selects a record from a database, and on submit the action is just "#" (or rather action="index.php") - I want to be able to add a ?hn=value_from_select before the action is submitted, so the actual url of the page changes to the direct link. I understand that for this I need ajax, but I'm a bit at a loss as to how I would do this.
I need more details, but as far as I understood, you are trying to submit a form to a specific option/location selected on the dropdown menu?, please send me more details via PM, and I will be able to help...
Well. I have a form, with the following code: <form method="post" action="<?php echo $domain.$page_path; ?>index.php"> HTML: Inside that form I have a select dropdown, which pulls information into <option>s from the database, like this: <option value="<?php echo $row['name']; ?>"><?php echo $human_name; ?></option> HTML: What I want, is for the value of the option selected (the $row['name']) to be appended to the action-part of the form - hence creating something like this: <form method="post" action="<?php echo $domain.$page_path; ?>index.php<?php echo $row['name']; ?>"> HTML: The above doesn't work, of course, since it has the following problems: the first time a user loads the page, it will be empty - the second time a user uses the drop-down, that value will be populated by the FORMER choice - not the current one. Hence the url will be wrong. Does it make more sense now?
Here is the Code! <form name="f"> </form> <select onchange="javascript:document.f.action=this.options[selectedIndex].value"> <option value="index.php">Index</option> <option value="game.php">Games</option> <option value="menu.php">Menu</option> <option value="forum.php">Forum</option> </select> Code (markup):
Thanks. That works, almost. Problem is that I need to add to the action already defined - not replace it entirely. Hence the <select onchange="javascript:document.f.action=this.options[selectedIndex].value"> HTML: needs to be something like this: <select onchange="javascript:document.f.action=<?php echo $domain.$page_path; ?>index.php?hn=this.options[selectedIndex].value"> <- which of course doesn't work - so how would I do this with the added php-variables? or just add the selected value to the already existing action. Nevermind, I figured it out! onchange="javascript:document.f.action=action + '?hn=' + this.options[selectedIndex].value" <- works just fine.