 |
| 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
|
|
|
|

February 19th, 2004, 01:58 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 19th, 2004, 03:27 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

February 19th, 2004, 03:33 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 19th, 2004, 03:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

February 20th, 2004, 07:06 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|
 |