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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.