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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.....:)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.