I am trying to select the email field in this iframe booking form. I eventually want to do something else with the field but for now as a test I just want to select the element and change the placeholder.
Getting this error so I am not selecting it correctly: Uncaught TypeError: Cannot set property 'placeholder' of null at HTMLButtonElement.changeCopy
You can view a live version of my code here and see the error in console when you click the button at the top: https://finnpegler.github.io/cart_recover/
I have also included the code as a snippet below but it throws a different error to do with cross origin frames.
var iframe = document.getElementById("booking-widget-iframe");
var field = iframe.contentWindow.document.querySelector("booking[email]");
function changeCopy() {
field.placeholder = "hello";
}
document.getElementById("button").addEventListener("click", changeCopy)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test site for Cart Recover Tool</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" media="screen" href="stylesheet.css" />
<link href="https://fonts.googleapis.com/css?family=Bree+Serif|Open+Sans&display=swap" rel="stylesheet">
<link rel="icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
Clicking this button should change the placeholder text in the email field below
<button id = "button">Click</button>
</body>
<script src="https://bettercleans.launch27.com/jsbundle"></script><iframe id="booking-widget-iframe" src="https://bettercleans.launch27.com/?w_cleaning" style="border:none;width:100%;min-height:2739px;overflow:hidden" scrolling="no"></iframe>
<script src="script.js"></script>