Add onclick property to input with JavaScript

input, javascript, onclick

Solution

Try this:

 input.onclick = function() { conn.send('$connect\r\n'); };

Steve

Problem

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?

Original source