473,385 Members | 1,615 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,385 software developers and data experts.

How to create a hidden input form element in javascript

4
Hi,

I am doing the following in a javascript function:

Expand|Select|Wrap|Line Numbers
  1. var hiddenElement = document.createElement("input");
  2. hiddenElement .setAttribute("type", "hidden");
  3. hiddenElement .setAttribute("name", ""hiddenElement");
  4. hiddenElement .setAttribute("id", "hiddenElement");
  5. hiddenElement .setAttribute("value", x.value);
  6. forms[formCount].appendChild(hiddenElement );
  7.  
I want to create this hidden input element in the parent form from where contol passes to this javascript function.

This is not working. Please help!

Thanks!
Jul 27 '07 #1
5 13261
gits
5,390 Expert Mod 4TB
hi ...

welcome to TSDN ...

as you can see, after i have applied the code-tags for you, we may notice the syntax-error in line 3. very easy (that will give you an js-error) ... there you have an error with the quotes ... fix it and it should work ...

when using the code tags you may find such simple errors very fast ... during developement you may also use firefox and the firebug extension locally that gives you a lot of hints on such errors when you try to execute the code ...

kind regards
Jul 27 '07 #2
bucchi
4
hi!!

Thanks for the reply! I modified parts of the code and have made some progress...

Now my problem is this..
I have a parent form from where the control has passed to a pop-up. Now is the JSP of the pop-up, I have a javascript which, based on some criteria, creates hidden elements in the parent form. How do i do that???

This is what i am doing in the pop-up...

Expand|Select|Wrap|Line Numbers
  1. var hiddenId = window.opener.document.getElementById(id).createElement("input");
  2. hiddenId.setAttribute("type", "hidden");
  3. hiddenId.setAttribute("name", "hiddenId");
  4. hiddenId.setAttribute("id", hiddenId);
  5. hiddenId.setAttribute("value", value);
  6. window.opener.document.getElementById(id).appendChild(hiddenId);
  7.  
But this is giving me error in the first line

Expand|Select|Wrap|Line Numbers
  1. var hiddenId = window.opener.document.getElementById(id).createElement("input");
This line is not working in the first place.. I want to create the hidden element in the parent form and not in this form.

Kindly help!!
Thanks!
Jul 31 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

you have to create your node in the document first and you append it to the form ... so simply remove the 'getElementById(id)' from your first line ...

kind regards
Jul 31 '07 #4
bucchi
4
thanks!

i did that.. It is creating the hidden element but it is not appending to the form

I can't seem to append the child to the parent form, from a pop-up JSP page which has this javascript function..
Is it not possible to append to a parent form?

Please help..
Aug 3 '07 #5
gits
5,390 Expert Mod 4TB
i tested it ... it is working (assuming id, value are correct) but, have a close look at your code ... i missed that too:

Expand|Select|Wrap|Line Numbers
  1. hiddenId.setAttribute("id", hiddenId);
you assign a node to the id ... don't do it ;)

and to prove that it is working ... set the type to 'text' ... so you may see the appended field appearing in your parent document

kind regards
Aug 3 '07 #6

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

Similar topics

8
by: Matt Herson | last post by:
I have been trying to find a way to use JavaScript to change the value of a hidden field on submit. I am already invoking a JavaScript to handle the validation on submit. The reason I need to...
1
by: Raghuram Banda | last post by:
Hi All, Can any one help me how to create a HIDDEN element using JavaScript (DOM) dynamically The following codes works fine with IE but not in Netscape currentElement =...
0
by: yurps | last post by:
Hello here is my html, if you click the missing image in the first column on the left, the div is shown, when clicked again the div disappears...but the bottom border disappears as well...Is there...
9
by: Randell D. | last post by:
Folks, I have a large amount of values to store (we're talking tens, if not hundreds of bytes). I need this for a client side application - ignore the security consequences for the moment -...
13
by: Geoff Cox | last post by:
Hello, How do I create a form without using document.write() which opens a new window? I imagine it has to do with using a <SPAN ID='idvalue' etc element and...
5
by: Phil Powell | last post by:
Requirement is to refresh a page in the form of a continual form submittal (for server-side validation and action) Here is the Javascript I came up with that I thought would do that: <script...
2
by: Bill Steele | last post by:
I want to have a window pop up with a form. When the form is submitted, it needs to pass along the URL of the original window. If find on th web eight gazillion descriptions of how to pass data...
4
by: Bosconian | last post by:
I've been fighting with this for an hour. My form contains a hidden input with the value initially set to "". When a user clicks on the link, a function is called that updates the hidden form...
11
by: newbie | last post by:
i have a form in which a hidden field (initial value as '0', and my javascript set it to '1' when an event is trigged). In the same form, i have a reset field. But I realized that the hidden field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.