Solution 1 :

I think, you should replace innerHTML with value in the second if.

function PriceRange() {
    var max = document.getElementById("maxprice").value,
        min = document.getElementById("minprice").value;

    if (min == "") {
      document.getElementById("minprice").value = 0;

    if (parseInt(max) <= parseInt(min)) {
        document.getElementById("maxprice").value = Number(document.getElementById("minprice").value) + 1;

    if (max == "") {
      document.getElementById("maxprice").value = 1000000;

Problem :

I’m trying to create a search filter that allows me to search items in my store. So I have 2 inputs and I want to be able to do the following.

  1. If my minimum price is empty then return 0 as a value to perform the search
  2. If maximum price is lower than minimum price then change the maximum price input into minimum price + 1 to perform the search
  3. If maximum price is empty then return infinite (or a really big number like 1000000) to perform the search

I’ve tried to create the script following that, but it didn’t work. So I’m not sure what I’m doing wrong.

I’ve updated the script with the help of @Craicerjack, but it still doesn’t work.

This is the html with the script.

Thank you so much for taking the time to help me!!

<form method="get" action="" target="_self">
  <div class="custom_range_widget">
    <input type="number" name="min_price" min="0" max="50000" placeholder="Min." contenteditable="true" id="minprice" />
    <input type="number" name="max_price" min="0" max="50000" placeholder="Max." contenteditable="true" id="maxprice" />

      function  PriceRange() {
        var max = document.getElementById("maxprice"),
        min = document.getElementById("minprice");

        if (min == "") {
          (int)document.getElementById("minprice").value = 0;

        if (parseInt(max) <= parseInt(min){
          (int)document.getElementById("maxprice").value = ((int)document.getElementById("minprice").innerHTML + (int)1);

        if (max == "") {
          (int)document.getElementById("maxprice").value = 1000000;
  <button type="submit" class="button">Filter</button>


Comment posted by Craicerjack

a couple of things.

Comment posted by Sanro

Ok, so, to see if I understand instead of using

Comment posted by Craicerjack

Yes thats one thing you should do.

Comment posted by Sanro

And I don’t understand what you said about “using variables that you haven’t defined”. mminprice I mistyped it here. But why does

Comment posted by Craicerjack

you have all these random

Comment posted by Sanro

Hi! I’ve this snippet and I’ve tried today and I cannot get it to work, even thought the debbuger says that there are no sintax mistakes and technically it should be working perfectly. I don’t know what might be missing.


Leave a Reply

Your email address will not be published. Required fields are marked *