<?php echo $this->getUrl(); ?>
gives me my index page url .i.e. www.domain.com/index.php/
But now, what I want is, when any particular option is selected, it should add to this url. .e.g.
www.domain.com/index.php/wordpress/
I write this code for it but now don know how to get it done. :(
<select onchange="setLocation('<?php echo $this->getUrl(); ?>')">
<option value=""> </option>
<option value="wordpress">Wordpress</option>
<option value="drupal">drupal</option>
<option value="magento">Megento</option>
</select>
Also, I had searched this link but couldn't take help from it. As it didnt work for me.
<select name="forma" ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value="Home">Home</option>
<option value="Contact">Contact</option>
<option value="Sitemap">Sitemap</option>
</select>
With this (note that I've added this
as the first argument):
<select onchange="setLocation(this, '<?php echo $this->getUrl(); ?>')">
<option value=""> </option>
<option value="wordpress">Wordpress</option>
<option value="drupal">drupal</option>
<option value="magento">Megento</option>
</select>
You could write the following JS:
function setLocation(elm, baseUrl) {
var keyword = elm.options[elm.selectedIndex].value; // Gets the selected keyword (some sanity check could be done)
window.location = 'http://' + baseUrl + keyword + '/'; // Redirects
}
Alternatively:
<select name="forma" onchange="window.location='http://<?php echo $this->getUrl(); ?>' + this.options[this.selectedIndex].value + '/';">
<option value="Home">Home</option>
<option value="Contact">Contact</option>
<option value="Sitemap">Sitemap</option>
</select>
(EDIT Prepended http://
to both examples.)