简体   繁体   中英

How to Change value of input after page loads?

I have used a range picker (Progress bar) to get measurements from the customers. I have set it's limit from 1 to 50 so it takes 1 value by default if user do not select it and user can add product to the cart without selecting range picker. Is there any way that we can change by default value on page load with javascript (No jQuery) to something that does not allow user to add product to the cart.

Link: https://cutt.ly/nrB4PAR

I am using this code now but it's not working. I want value to be null.

<script type="text/javascript" language="javascript">
    debugger;

    var range_val = document.getElementById("tmcp_range_1").value;
    if (range_val == 1)
        {
         document.getElementById("tmcp_range_1").value = "";
        }
    
</script>

在此处输入图片说明

UPDATED:

在此处输入图片说明

I'm not sure I really understand why you need this, but you have to put that code in a function, then call an event listener.

function changeVal() {
  var range_val = document.getElementById("tmcp_range_1").value;
  if (range_val == 1) {
    document.getElementById("tmcp_range_1").value = "22";
  }
}

window.addEventListner("load", changeVal);

Updating the input value after DOM loads will change the value.

function updateVal() {
    var range_val = document.getElementById("tmcp_range_1").value;
    if (range_val == 1) {
        document.getElementById("tmcp_range_1").value = "22";
    }
}
window.addEventListner("load", updateVal);

And also you need to change noUiSlider logic to update UI. Ref link https://refreshless.com/nouislider/slider-read-write/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM