function init_button(){ var price = document.querySelector('.price p').innerHTML; var price = price.replace(/[^0-9-.]/g, ''); var model = document.querySelector('.page-title h3').innerHTML; var qty = document.getElementsByName("quantity")[0].value; if(isNaN(price)) return; if(!model) return; if ((parseInt(qty) * parseFloat(price)) < 100){ document.getElementById('approve_button_id').style.display = "none"; return; } var new_button = document.createElement('approve-button'); new_button.id = "approve_button_id"; new_button.style.display="inline-block"; new_button.style.margin="25px auto"; new_button.setAttribute('application-type',"embedded_app"); if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { var rfq_btn = document.querySelector('.product-info'); } else { var rfq_btn = document.querySelector('#box-category'); new_button.style.width="100%"; new_button.style.textAlign="center"; } rfq_btn.after(new_button); document.getElementById('approve_button_id').setAttribute('price',price); document.getElementById('approve_button_id').setAttribute('model',model); document.getElementById('approve_button_id').setAttribute('qty',qty); document.getElementById('approve_button_id').setAttribute('type',"new_product"); } function update_qty(qty){ document.getElementById('approve_button_id').setAttribute('qty',qty); } init_button(); var qty_ele = document.getElementsByName("quantity")[0] qty_ele.addEventListener('change',event => { var qty = parseInt(document.getElementsByName("quantity")[0].value); var btn_qty = document.getElementById('approve_button_id').getAttribute('qty'); if (parseInt(qty) != parseInt(btn_qty)){ update_qty(qty); } })