Hi
I added some codes and add this to search-sidebar.php :
<script type="text/javascript">
//remove comma from number
function removeCommas(str) {
return(str.replace(/,/g,''));
}
// insert commas as thousands separators
function addCommas(n){
var rx= /(\d+)(\d{3})/;
return String(n).replace(/^\d+/, function(w){
while(rx.test(w)){
w= w.replace(rx, '$1,$2');
}
return w;
});
}
// return integers and decimal numbers from input
// optionally truncates decimals- does not 'round' input
function validDigits(n, dec){
n= n.replace(/[^\d\.]+/g, '');
var ax1= n.indexOf('.'), ax2= -1;
if(ax1!= -1){
++ax1;
ax2= n.indexOf('.', ax1);
if(ax2> ax1) n= n.substring(0, ax2);
if(typeof dec=== 'number') n= n.substring(0, ax1+dec);
}
return n;
}
window.onload= function(){
var n1= document.getElementById('priceMin'),
n2= document.getElementById('priceMax');
n1.value = n2.value='';
n1.onfocus=n1.onkeyup= n1.onchange=n2.onfocus=n2.onkeyup=n2.onchange= function(e){
e=e|| window.event;
var who=e.target || e.srcElement,temp;
temp= validDigits(who.value,2);
who.value= addCommas(temp);
}
n1.onblur=n2.onblur= function(){
var temp=n1.value;
var temp2=n2.value;
if(temp)n1.value=removeCommas(temp);
if(temp2)n2.value=removeCommas(temp2);
}
n1.onkeypress=n2.onkeypress= function(event) {
if (event.which == 13 || event.keyCode == 13) {
var temp=n1.value;
var temp2=n2.value;
if(temp) n1.value=removeCommas(temp);
if(temp2)n2.value=removeCommas(temp2);
return false;
}
return true;
}
}
</script>
I added these to older code:
//remove comma from number
function removeCommas(str) {
return(str.replace(/,/g,''));
}
n1.onkeypress=n2.onkeypress= function(event) {
if (event.which == 13 || event.keyCode == 13) {
var temp=n1.value;
var temp2=n2.value;
if(temp)n1.value=removeCommas(temp);
if(temp2)n2.value=removeCommas(temp2);
return false;
}
return true;
}
And i changeed a section to this:
n1.onblur=n2.onblur= function(){
var temp=n1.value;
var temp2=n2.value;
if(temp)n1.value=removeCommas(temp);
if(temp2)n2.value=removeCommas(temp2);
}
Now when visitor type in price search box its show separators but when click out of box its remove separators.
New Problem:
After typing in price search box pressing enter key can not submit and only click on button do search.
I added this code:
n1.onkeypress=n2.onkeypress= function(event) {
if (event.which == 13 || event.keyCode == 13) {
var temp=n1.value;
var temp2=n2.value;
if(temp) n1.value=removeCommas(temp);
if(temp2)n2.value=removeCommas(temp2);
document.getElementsByTagName("button").click(); <---------------------added this-----------------
return false;
}
return true;
}
and now pressing enter key cause submiting form but one of box send by get in url price with comma separator therefore search can not work correctly.