Matty999555 Posted June 20, 2010 Share Posted June 20, 2010 I have this form here: <html> <head> <script type="text/javascript" language="javascript"> function createDiv() { var Tag = document.createElement("input"); Tag.id = "url_name[]"; Tag.type = "text"; Tag.value = "Insert Name Here"; Tag.onfocus = "if(this.value=='Insert Name Here')this.value='';"; Tag.onblur = "if(this.value=='')this.value='Insert Name Here';"; document.getElementById("input").appendChild(Tag); var Tag = document.createElement("input"); Tag.id = "url_url[]"; Tag.type = "text"; Tag.value = "Insert URL Here"; Tag.onfocus = "if(this.value=='Insert URL Here')this.value='';"; Tag.onblur = "if(this.value=='')this.value='Insert URL Here';"; document.getElementById("input").appendChild(Tag); var Tag = document.createElement("br"); document.getElementById("input").appendChild(Tag); } </script> </head> <body> <p align="center"> <b>Click this button to create div element dynamically:</b> <input id="btn1" type="button" value="create div" onclick="createDiv();" /> </p> <div id="input"> <input id="url_name[]" type="text" value="Insert Name Here" onfocus="if(this.value=='Insert Name Here')this.value='';" onblur="if(this.value=='')this.value='Insert Name Here';" /> <input id="url_url[]" type="text" value="Insert URL Here" onfocus="if(this.value=='Insert URL Here')this.value='';" onblur="if(this.value=='')this.value='Insert URL Here';" /> <br /> </div> </body> </html> It SHOULD create two inputs with onfocus and onblur attributes but It doesn't. Can someone tell me what I am doing wrong. Thanks Link to comment https://forums.phpfreaks.com/topic/205320-creating-inputs/ Share on other sites More sharing options...
Matty999555 Posted June 20, 2010 Author Share Posted June 20, 2010 Realised my mistake. I was Doing Tag.onfocus istead of Tag.setAttribute("onfocus", ""); Solved Link to comment https://forums.phpfreaks.com/topic/205320-creating-inputs/#findComment-1074617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.