Jump to content

"change" get request - multiple <select> I have: myDD=1&myDD=2, I want : myDD=1,2....


roberto68

Recommended Posts

I have multiple select (Drop down list) - I select options from that DD list and post that to another page. Now my url link looks like that

http://localhost/map.php?mydropdown1=1&mydropdown1=2

and I want my Url link look like that (javascript, php) it is easier to parse

http://localhost/map.php?mydropdown1=1,2

I select categories in that DDlist and on the other page (map.php) smth is performed (javascript) according to selected categories. I've function like this to retrieve url variables on map.html (it's working fine)

function getUrlVars() { // get  category id = number from the form(DDlsit)    var vars = {};    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {        vars[key] = value;    });    return vars;}
Link to comment
Share on other sites

It sounds like you are actually making a GET request then. What would help is the form / code that generates the URL

Link to comment
Share on other sites

<form name="dropdowns" id="dropdowns"><label for='educationForm'>select what you wanna learn<br><div align="center"><select multiple="multiple" name="mydropdown1" id="dd1"><optgroup label="education"><option value="1">IT-programing</option><option value="2">IT-sys_admin</option><option value="3">IT</option><option value="4">science</option><option value="5">electronic engineering</option><option value="6">math&physics</option><option value="7">mechanical_engineering</option></optgroup>......</select></label></form>

ok so here's my html

Link to comment
Share on other sites

If you name it "mydropdown1[]" then PHP will interpret it as an array and you will be able to access the values as $_GET['mydropdown1'][0], $_GET['mydropdown1'][1] and so on.

Link to comment
Share on other sites

The browser is submitting the data correctly, that's how it is supposed to submit it. Your function that gets URL variables is not set up to check for the existence of multiple values for the same variable. You could change that function so that if a value already exists then it turns the original value into an array with the first value, then adds the new value. If it's already an array then just add the new value. You'll end up with an array of values for things that are submitted with multiple values. That's a lot easier than trying to override how the browser submits data.

Link to comment
Share on other sites

the URL is still the same though, I need only those category numbers

so how would it look like ? my full url is

http://localhost/map.php?mydropdown1=2&mydropdown1=3

and I need only those numbers 2,3 ... so how woudl completer code look like

funtion getULRvars(){$url = _POST['mydropdown1'];$myArray1 = explode('&', $url);$myArray2 = explode('=', $myArray1);
and $params'd be thing I want ?? or rahter do it with that JS funciton I posted ?
Edited by roberto68
Link to comment
Share on other sites

If you're trying to get the data in PHP then, like Ingolme said, if you add square brackets to the end of the name then PHP will automatically create an array of values. If you're trying to get the data in Javascript then you need to change that function you posted in the first post to create an array of values with the same name instead of overwriting the value. It doesn't check if a value already exists with that name, it just overwrites whatever is there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...