Jump to content

Want to send multiple selects as one input.


Alonski

Recommended Posts

I have two drop down menus that each have different things in them. I choose both of them. When I submit "x" in one menu and "y" in another I want it to work so that the url will be

something.com/?keyword="x+y"

 

How would I go about doing this?

 

I tried doing this but it didn't work:

<?php $key=""; ?>
<script>
function h(dd) 
{
var idx = dd.selectedIndex;
  var val = dd[idx].label;
return "\"" + val + "\"";
}
</script>

  <tr>
  	<td span="2">
    	<form action="<?php echo $mm_action_url."index.php" ?>" method="get">
      	<select name="keyword" onChange="h(this);">
				<option label="Select Car">Select Car</option>
				<option label="אאודי">אאודי</option>
				<option>אונדה</option>
			</select>
        <input class="button" type="submit" name="Search" value="<?php echo $VM_LANG->_('PHPSHOP_SEARCH_TITLE') ?>" />
        <input type="hidden" name="keyword" value="<?php echo $key;?>" />
			<input type="hidden" name="Itemid" value="<?php echo intval(@$_REQUEST['Itemid']) ?>" />
			<input type="hidden" name="option" value="com_virtuemart" />
			<input type="hidden" name="page" value="shop.browse" />
      </form>
    </td>
  </tr>

you could do this:

 

<form id="searchForm" method="get">
<select id="keyword" name="keyword" multiple="multiple">
<option>Select Car</option>
<option value="Car 1">Car 1</option>
<option value="Car 2">Car 2</option>
</select>
<input type="submit">
</form>

 

then; let you PHP file sort out each different keyword

you could also do something like this:

 

<script type="text/javascript">

function redirect() 
{
var kw = document.getElementById("kwblender").value;
if (kw.length >= 1)
{
document.location.replace("?keywords=" + kw);
}
setTimeout("redirect()",100);
}

function findCar()
{
var my_url = document.location.href;
var pre_kw = my_url.split("?")[1];
var pro_kw = pre_kw.split("keyword=");
for (i=1;i<=pro_kw.length;i++) 
{
if (i < pro_kw.length-1)
{
document.getElementById("kwblender").value += pro_kw[i].split("&")[0] + "+";
}
else {
document.getElementById("kwblender").value += pro_kw[i].split("&")[0];
}
}
}

window.onload = function() {
redirect();
setTimeout("findCar()",100);
}

</script>

<form id="searchForm" method="get">
<select id="keyword" name="keyword" multiple="multiple">
<option>Select Car</option>
<option value="Car 1">Car 1</option>
<option value="Car 2">Car 2</option>
</select>
<input type="submit">
<!-- Add The Hidden Field Below To Your Form -->
<input type="hidden" id="kwblender">
</form>

 

but you would have your initial form page loaded again; after you submit your data. so in that regard; if that is an issue for you, then you might want to go with my first suggestion of letting a server side language handle your keyword(s) substring query. i was just messing around and thought i would try to see what i could do on the client side (using javascript) too accomplish what you were wanting to do and the above is what i came up with. hope this is close to what you were looking for and good luck.

 

edit/update: you could use ajax to submit your form data back to your form page (that contains code above); that way you initial form page does not have to reload - just an idea.....:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.