lisovaccaro
lisovaccaro

Reputation: 33956

Add hidden value to form field

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

Answers (3)

subhaze
subhaze

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

Pradeep Singh
Pradeep Singh

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

Ish
Ish

Reputation: 29536

Using jQuery

$('#source').change(function() { 
    $('#target').val("#"+$(this).val()+"#") 
});

Upvotes: 0

Related Questions