Here is my HTML and JS Code:
function errorMessage(){ if(document.getElementsByTagName('textarea')['shipAddress'].value==''){ document.getElementById('shipSubtotal').style.cssText='color: red; font-weight: bold;'; document.getElementById('total').style.cssText='color: red; font-weight: bold;'; document.getElementById('shipSubtotal').innerHTML='Please enter your address.'; document.getElementById('total').innerHTML='Please enter your address.'; } else{ document.getElementById('shipSubtotal').innerHTML=''; document.getElementById('total').innerHTML=''; } }
<!doctype html> <html lang="en"> <body> <div> <p> Shipping Address: <br> <textarea name="shipAddress" id="addressInput" cols="30" rows="5" placeholder="Please enter your address." onchange="errorMessage()"></textarea> </p> <p> Merchandse Subtotal: <span id="merchandSubtotal"></span> </p> <p> Shipping Subtotal: <span id="shipSubtotal"></span> </p> <p> Total Payment: <span id="total"></span> </p> <p> <input type="submit" value="Checkout" onclick="checkoutButton()"> </p> </div> </body> </html>
I think you are looking for DOMContentLoaded event
window.addEventListener('DOMContentLoaded', (event) => { console.log('DOM fully loaded and parsed'); errorMessage(); })
1.4m articles
1.4m replys
5 comments
57.0k users