loading external secure website and acquiring the specific id to set the value?

I am trying to create a site where I can retrieve the id of a specific element and set it’s value. I have tried doing this:

<!DOCTYPE html>
<html>
    <head>help</head>
    <script type="text/javascript">
    function getField(){ 
        window.addEventListener('load', function(){
            console.log('hi')
            console.log(document.getElementById('change_request.short_description').value)

        });
        //document.getElementById('change_request.short_description').value='hello';             
    }   

    </script>

    <body>
        <a href="xxxx.com"  target="_blank" onclick="getField()">SNOW CHANGE</a>
              

    </body>
</html>

But my console shows nothing. I am thinking since it is a secure website, I cannot access the id.

But I don’t really know whether this is plausible. My question is how do you load the external website then acquire the specific id to set the value?

Thank you for the help.

10 thoughts on “loading external secure website and acquiring the specific id to set the value?”

  1. It’s hard to understand what you’re trying to do. Do you want to get and element from xxxx.com? If yes then you can’t just do that. Otherwise, the element is on the same page, you need to wrap the function inside the load event or remove the load completely. Also, in your getElementById you have a "." which suggests class name. You can’t do that. Use
    querySelectorAll instead and [0] to get the first element only.

    <!DOCTYPE html>
    <html>
    
        <script type="text/javascript">
        window.addEventListener('load', function(){
        console.log('Window Loaded');
            window.getField = function(){ 
    
                  console.log('hi')
                  console.log(document.querySelectorAll('#change_request.short_description')[0].value)
    
              //document.getElementById('change_request.short_description').value='hello';             
            }   
        });
        </script>
    
        <body>
            <a href="xxxx.com"  target="_blank" onclick="getField()">SNOW CHANGE</a>
            <input id="change_request" class="short_description" value="123" type="text" />
    
        </body>
    </html>
    Reply

Leave a Comment