I am creating a user input at one of the events:
var throwConnectBox = function() { chat_box = document.getElementById('box'); div = window.parent.document.createElement('div'); input = window.parent.document.createElement('input'); input.type = "submit"; input.value = "Join chat"; input.onclick = "conn.send('$connect\r\n');"; div.appendChild(input); chat_box.appendChild(div); }
... but the resulting input does not have onclick property. I tried to use
input.onclick = conn.send('$connect\r\n');
... instead, but didn' work either. What am I doing wrong?
Description. The onclick property of an Input object specifies an event handler function that is invoked when the user clicks on the input element. It is not invoked when the click( ) method is called for the element. Only form elements that are buttons invoke the onclick event handler.
The onclick attribute is part of the Event Attributes, and can be used on any HTML elements.
Try this:
input.onclick = function() { conn.send('$connect\r\n'); };
Steve
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With