Meaning of part of JavaScript code

2

I built a code to prevent my search engine from doing searches with the search field blank or with the default message that appears in the value, I received a part of the code and when implementing it appeared an error that did not happen before in layout , there is a small part of the code that I do not have the knowledge of what it does and that it did not have in the code before and the error did not appear.

I have the following code:

<form name="produtosBuscaForm" method="get" action="http://busca.exemplo.com.br"  onsubmit="return ajaxsearchsubmit(this)">  

        <!--!! <input type="hidden" name="Categoria" value="0" id="categoria"> !!-->
        $&{<input type="hidden" name="view" value="(view)" />}       
                 <div class="busca">
         <div class="inputbusca">
            <input type="text" name="w" maxlength="35" value="Digite a busca" onfocus="if(this.value == 'Digite a busca') { this.value = ''; }" onblur="if(value=='') value ='Digite a busca'"id="sli_search_1" autocomplete="off" style="font-family:Verdana, Geneva, sans-serif;font-style:italic;font-weight:lighter;font-size:12px;color:#999999;outline:none;">
         </div>
                    <a href="javascript:return ajaxsearchsubmit(document.produtosBuscaForm);" class="ok"></a>
                 </div>                 
    </form>

My question is regarding the following part:

 <!--!! <input type="hidden" name="Categoria" value="0" id="categoria"> !!-->
        $&{<input type="hidden" name="view" value="(view)" />}   

The commented part OK, but what would be the $&{ } command? Could this part be causing me the error?

    
asked by anonymous 23.05.2014 / 15:01

1 answer

1

$& references JavaScript function String.replace() .

It simply means that replace must be done throughout the current text.

Here's a simple example using $& :

if (typeof String.prototype.highlight !== 'function') {
    String.prototype.highlight = function (match, spanClass) {
        var pattern = new RegExp(match, "gi"),
            highlight = "<span>$&</span>";

        return this.replace(pattern, highlight);
    }
}

Sete a JSFiddle with another simple example

Here is the jsfiddle code:

var value = "My number is 212-555-1234.";
var pattern = new RegExp( "(\d+)", "g" );

var result = value.replace(
    pattern,
    "[$&]"
);

alert( result );

I hope it helps.

    
23.05.2014 / 16:14