0

I have this url :

http://test.dev/search?publishing_types%5B%5D=Selling&prop_category%5B%5D=Apartment+%26+housing&priceFrom=0&priceTo=300000&areaFrom=0&areaTo=300000&yearFrom=1900&yearTo=2017 

In fuction i check full url and i want to add checkbox for that value if exists in url. Any suggesion?

  function existingUrl(fullUrl){
          $('.dataurl').each(function(){
            var hasValue =  fullUrl.indexOf($(this).val());
            if(hasValue != -1)
              this.checked = true;

        });
      }

HTML:

  @foreach($prop_types as $index => $prop_type)
     <p class="customCheckBox no-padding-left">
        <input type="checkbox" class="preventUncheck dataurl" name="publishing_types[]" id="toggle-on{{ $index }}" value="{{ $prop_type }}" >

        <label for="toggle-on{{ $index }}" class="checkboxTitle">{{ $prop_type }}</label>
     </p>
   @endforeach
uzhas
  • 895
  • 4
  • 13
  • 27

1 Answers1

1

To get the clean text you need to decode the URI and replace any remaining codification. Assuming you have a string variable you can do this as below.

See this question for a longer explanation.

var str = 'Apartment+%26+housing';
console.log('value=' + decodeURIComponent( str.replace(/\+/g, '%20') ));
Community
  • 1
  • 1
Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67