Wrox Programmer Forums
|
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
 
Old February 19th, 2004, 01:58 PM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding dynamic input

I've create a function to add a new input.

Code:
function getNewInput(inputName)
{
var newInput = document.createElement('input');

newInput.setAttribute('type','"text"');
newInput.setAttribute('id','"' + inputName + '"');
newInput.setAttribute('name','"' + inputName + '"');
newInput.setAttribute('className','inputText');
newInput.setAttribute('onkeydown','"if(event.keyCode!=13){beginEdit();}"');

return(newInput);
}
My problem is the name attribute is not set. What is wrong?

Stéphane Lajoie
__________________
Stéphane

A programmer is a device that transform coffee in code lines

\"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.\" Rich Cook
 
Old February 19th, 2004, 03:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Is the name not set? Or the className?

If it's the name, I don't understand why it doesn't work. This code looks fine to me. Is this all the code you have?

If it's the className, ir's because you give it a value of inputText instead if inputName.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 19th, 2004, 03:33 PM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My problem is with the name attribute.

I change method for creating the input. Now I create the all the input in HTML and create it. Seen to correct all my problem.

Stéphane Lajoie
 
Old February 19th, 2004, 03:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's still odd. I used your code, and then used the alert method to alert the name of the new object I just created. Worked fine for me (tested it in IE6)

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 20th, 2004, 07:06 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Names cannot be added like this, don't ask me why. Although it is added as an attribute thee form does not recognise it. You need to create the element in a different way:
Code:
function getNewInput(inputName)
{
var newInput = document.createElement('<input name=\"' + inputName + '\">');

newInput.setAttribute('type','"text"');
newInput.setAttribute('id','"' + inputName + '"');
newInput.setAttribute('className','inputText');
newInput.setAttribute('onkeydown','"if(event.keyCode!=13){beginEdit();}"');

return(newInput);
}
Works in IE, don't know for NN.

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Buttons,SaveToolStrip, adding records KeviJay VB Databases Basics 2 May 28th, 2008 12:46 PM
Adding Input Boxes ann86 Beginning PHP 1 April 7th, 2008 04:06 AM
dynamic <input> tag Val Javascript 1 September 6th, 2006 02:55 AM
Adding onclick stuff to an INPUT via javascript p.ross BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 November 29th, 2005 01:08 PM
Adding dynamic fields ivnavin Crystal Reports 0 December 17th, 2004 03:35 PM





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