473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problems with createElement("input")

1
I am having trouble creating a hidden form field, or least having it accessible from getElementById.

Rough overview:

I am reading an XML file through XMLhttpRequest and outputting each item into a unique div tag, which has a dynamically generated name, then appending each div tag to an existing div tag. This is working A-OK.

Here's the problem:

Basically so I can show a general section - ie. Bookmarks, Blog Posts, etc - then show or hide specific items within each section. I want to be able to show the next or previous X items through another javascript function, but the number of items can cahnge with each refresh of the page, so to be able to tell how many items are contained within each section's div tags i am creating two hidden form input at the end of writing the items. One is the total number of items in the section, the other value is the starting number of the currently displayed items. I am placing these two values into a form which is created.

here's the code to create the form as well as the inputs
Expand|Select|Wrap|Line Numbers
  1. // create form
  2.                 newHiddenForm = document.createElement("form");
  3.                 newHiddenForm.name = newFormName;
  4.                 newHiddenForm.id = newFormName;
  5.                 document.body.appendChild(newHiddenForm);
  6. //create input for total
  7.                 newHiddenInput1 = document.createElement("input");
  8.                 newHiddenInput1.type = "hidden";
  9.                 newHiddenInput1.name = totalFormName;
  10.                 newHiddenInput1.id = totalFormName;
  11.                 newHiddenInput1.value = i; // i is the loop limiter
  12.  
  13. // create input for start value
  14.                 newHiddenInput2 = document.createElement("input");
  15.                 newHiddenInput2.type = "hidden";
  16.                 newHiddenInput2.name = startFormName;
  17.                 newHiddenInput2.id = startFormName;
  18.                 newHiddenInput2.value = 0;
  19.  
  20. //append the two inputs to the form
  21.                 mainFormElement = document.getElementById(newFormName);
  22.                 mainFormElement.appendChild(newHiddenInput1);
  23.                 mainFormElement.appendChild(newHiddenInput2);
  24.  
  25.  
  26.  
this doesnt give me any errors when the script is run, but when i try to access it from another javascript function it tells me that it has no properties

Expand|Select|Wrap|Line Numbers
  1.             totalObj = document.getElementById(totalName);
  2.             totalItems = totalObj.value
  3.  
i have checked to make sure that the 'totalName' in the above is the same as the name being written to the input tag.

Any suggestions?
Oct 18 '06 #1
1 2641
acoder
16,027 Expert Mod 8TB
It should be the same as the ID, not the name.
May 23 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Christoph | last post by:
newFieldElement = document.createElement( 'INPUT' ); newFieldElement.onblur = new Function( "calculatePremiumOptionTotal( this );" ); In my (dynamically generated) javascript, I've never had a...
2
by: Steve Holden | last post by:
I'm trying to copy data from an Access database to PostgreSQL, as the latter now appears to work well in the Windows environment. However I'm having trouble with date columns. The PostgreSQL...
2
by: lgo | last post by:
I have read several variations of this topic posted on this news group. However I was not able to find the answer for my problem. I am trying to build code (see below) to update a large single...
4
by: Chad Micheal Lawson via .NET 247 | last post by:
I'm stumped at this point and I'm tired of trying things so I'mposting in hopes of some guru with a sharp eye. I have anasp.net app running on a local Win XP Pro box. Within the app,I call a SPROC...
1
by: James Pose | last post by:
Convert.Int32 fails for "0" but works fine for all other numbers. This does not work on one machine when "0" it works fine on other machines Convert.ToInt32(“0”); gives exception {"Input...
2
by: danny.dion | last post by:
Hi ! I have a question about JScript : I have an object class wich dynamically creates a control in the page. Then it binds an event to that control, pointing on one of its methods (the...
12
by: ssh | last post by:
function testfn(name) var tbody = document.getElementById('hellospace').getElementsByTagName('tbody'); var row = document.createElement('TR'); var cell1 = document.createElement('TD');...
5
by: Jeremy | last post by:
Is there any good reading about pitfalls of scoping when using events? Here is my specific issue: function MyType() { this.foo = "bar"; this.textbox = document.createElement("input");...
1
by: mowsen | last post by:
Hey, simple thing. I try to create a new button which holds a function as "onclick" attribute. I tried different ways, varried here and there but without success. The function in question looks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.