Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 23rd, 2003, 05: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.
Reply With Quote
  #2 (permalink)  
Old July 29th, 2003, 04:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,731, Level: 42
Points: 9,731, Level: 42 Points: 9,731, Level: 42 Points: 9,731, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,068
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Assuming you have a form named 'frmUsers':
Code:
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);

--

Joe
Reply With Quote
  #3 (permalink)  
Old July 29th, 2003, 05:03 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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);
[/code]


/Robert
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 07:56 PM
Generating html tags dynamically sachin lad Servlets 2 May 1st, 2007 05:46 PM
Can I add code to title tags? wehaveasolution ASP.NET 1.0 and 1.1 Basics 0 October 10th, 2005 10:59 AM
Stripping specific tags from input XML EstherMStrom XSLT 3 December 13th, 2004 01:04 PM



All times are GMT -4. The time now is 03:44 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.