Reputation: 33956
I want to add a value to my search form that is invisible for the users so that when they look for pizza they are actually searching for: #pizza#
I'm using wordpress and I use this code for the search form.
<li id="search-10" class="widget_search"><form role="search" method="get" id="searchform" action="http://chusmix.com/">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s" style="margin-left:418px;">
<input type="submit" id="searchsubmit" value="Buscar">
</div>
</form>
</li>
Upvotes: 1
Views: 2052
Reputation: 8855
this should work: Example
JavaScript
function wrapSearch() {
var text = document.getElementById('s');
text.value = "#" +text.value+ "#";
}
HTML added onsubmit="wrapSearch()"
to the form tag
<li id="search-10" class="widget_search"><form role="search" method="get" id="searchform" action="http://chusmix.com/" onsubmit="wrapSearch()">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s" style="margin-left:418px;">
<input type="submit" id="searchsubmit" value="Buscar" >
</div>
</form>
</li>
Upvotes: 2
Reputation: 3634
<script>
function searchValue(val)
{
if(val.value!='')
{
val.value = "#"+val.value+"#";
return true;
}
else
{
return false;
}
}
</script>
<input type="submit" id="searchsubmit" value="Buscar" onclick="return searchValue(document.getElementById('s'));">
Upvotes: 1
Reputation: 29536
Using jQuery
$('#source').change(function() {
$('#target').val("#"+$(this).val()+"#")
});
Upvotes: 0