Advertisement:

Author Topic: search price Input field thousand separator problem. please help  (Read 714 times)

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Hi.
For better for user of osclass system i think ,when a visitor type in max and min search box thousand separator can help him.

i add this code to search-sidebar.php in bender
Code: [Select]
<script type="text/javascript">
// 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');
    var n2= document.getElementById('priceMax');
   
    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=parseFloat(validDigits(n1.value)),
        temp2=parseFloat(validDigits(n2.value));
        if(temp)n1.value=addCommas(temp);
        if(temp2)n2.value=addCommas(temp2);
    }
}
</script>

Now when a visitor type in price search box real time it change price format: 55555 => 55,555

Problem:
It can not search!!!
in url we sea:
Quote
index.php?page=search&sOrder=dt_pub_date&iOrderType=desc&sPriceMax=55,555     Do not show search result
therfore it can not search
but if we edit url in browser by remove (,) and chenge 55,555 to 55555 search work and show result.
Quote
index.php?page=search&sOrder=dt_pub_date&iOrderType=desc&sPriceMax=55555         Can show search result

please help. and say me how i can use price format ability for search prices widout search problem?

thanks



« Last Edit: August 19, 2016, 12:17:16 am by abc500x500 »

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: search price Input field thousand separator problem. please help
« Reply #1 on: August 19, 2016, 12:21:53 am »
Also i added this code:

Code: [Select]
<script type="text/javascript">
// 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('price');
     

    n1.onkeyup= n1.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= function(){
        var temp=parseFloat(validDigits(n1.value));
        if(temp)n1.value=addCommas(temp);
       
    }
}
</script>

to item-post.php and not seen any problem for submiting ads or editing ads.

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: search price Input field thousand separator problem. please help
« Reply #2 on: August 19, 2016, 03:31:05 pm »
Hi
I added some codes and add this to search-sidebar.php :

Code: [Select]
<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:

Code: [Select]
//remove comma from number
function removeCommas(str) {
    return(str.replace(/,/g,''));
}

Code: [Select]
    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:
Code: [Select]
    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:
   
Code: [Select]
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.
« Last Edit: August 19, 2016, 07:01:49 pm by abc500x500 »