Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 5th, 2006, 01:32 PM
Val Val is offline
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamic <input> tag

I have a simple form:

<form id="form" action="#">
<input type="text" id="2" name="2" size="40" onclick="alert('ok-2')"></input>
</form>

and I want to create dynamically once more <input> tag inside this form.
My problem is - after creating tag, onclick method doesn't work.

So, what I did

<form id=form action="#">
<input type="text" id="2" name="2" size="40" onclick="alert('ok-2')"></input>
</form>

<input type=button onclick=javascipt:writeline("3") value="create tag input"> </input>

<script language="JavaScript" type="text/javascript">

function writeline(str) {
var oForm = document.getElementById("form");//
var oInput = document.createElement("input");
oInput.setAttribute("type", "text");
oInput.onclick="alert('ok-3')";
oInput.id=str;
oInput.name=str;
oForm.appendChild(oInput);
}// end of writeline(str)

</script>

Any ideas?


  #2 (permalink)  
Old September 6th, 2006, 02:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Try
Code:
oInput.onclick = function() {alert("ok-3");};
Be warned that version of IE before 6 won't submit the name of the button when posting. You probably don't need it anyway but if you do see: http://windowssdk.msdn.microsoft.com.../ms534184.aspx

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
<a> tag in XML sani723 XSLT 5 March 27th, 2007 04:16 AM
Problem with <span> tag tclotworthy XSLT 2 February 18th, 2007 03:48 PM
get displayed name of the <select> tag nikeshkm HTML Code Clinic 1 October 20th, 2006 11:21 PM
<Form> tag within <form> tag rit01 ASP.NET 2.0 Basics 3 April 23rd, 2006 08:12 AM
Dynamic HTML <<Events>> babloo81 Javascript 2 December 29th, 2003 12:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.