Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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
Old July 23rd, 2003, 04:33 PM
Authorized User
Join Date: Jun 2003
Location: Livermore, CA, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically Add input tags

I have a text box with a search button. Type in the first name of a user in the text box and click search. New window pops up with a list of people matching the text box. Click Add User. The Selected user is added to a list on the main window, and the opened window is closed.
Now I have a user List. But the user list is not contained in the Form Collection as they are not part of an input type.

How would I add a <input type='hidden' name='UserList' value=> tag when the user Finds the user? I also need the ability to add more than one.
Old July 29th, 2003, 03: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

Assuming you have a form named 'frmUsers':
function addInput(Name, Value, Parent)
  var oInput = document.createElement("<input name=\"" + Name + "\">");
  oInput.type = "text";
  oInput.value = Value;
  return Parent.appendChild(oInput);

//Example call:
addInput("UserList", "Joe", document.frmUsers);


Old July 29th, 2003, 04:03 AM
Authorized User
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts

createElement should be used like this (to achieve a more stable version across browsers and platforms):
  var oInput = document.createElement("input");
  oInput.setAttribute("name", Name);
  oInput.setAttribute("type ", text);
  oInput.setAttribute("value ", Value);
  return Parent.appendChild(oInput);

//Example call:
addInput("UserList", "Joe", document.frmUsers);


Similar Threads
Thread Thread Starter Forum Replies Last Post
add HTML tags via XSLT chopswil2 XSLT 3 November 5th, 2007 09:30 AM
Read input from Dynamically Controls sois C# 3 August 20th, 2007 06:56 PM
Can I add code to title tags? wehaveasolution ASP.NET 1.0 and 1.1 Basics 0 October 10th, 2005 09:59 AM
Generating html tags dynamically sachin lad Servlets 1 April 26th, 2005 05:35 PM
Stripping specific tags from input XML EstherMStrom XSLT 3 December 13th, 2004 01:04 PM

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