473,570 Members | 2,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem accessing hidden variable in FIREFOX

Hello all,

In some hidden variable (<input type="hidden" name="hiddenId"
value="test" /> ,i stored some value.I accessed the value "test" using

var id = document.getEle mentById( 'hiddenId' );

It is working fine in IE. But in Mozilla Firefox , null value is
returned.Is there any way to use hidden variables compatible to
browsers......?

I don't know browser compatibility in javascript.Can anyone help me to
tackle this problem........ .

Thanks,
karthik

Jan 13 '06 #1
19 10527
k.*********@gma il.com said the following on 1/13/2006 2:43 AM:
Hello all,

In some hidden variable (<input type="hidden" name="hiddenId"
value="test" /> ,i stored some value.I accessed the value "test" using
Thats not a hidden variable, its a hidden input.
var id = document.getEle mentById( 'hiddenId' );
How is Firefox supposed to find it by ID when the input has no ID? IE
incorrectly grabs it based on the NAME attribute.
It is working fine in IE. But in Mozilla Firefox , null value is
returned.Is there any way to use hidden variables compatible to
browsers......?

I don't know browser compatibility in javascript.Can anyone help me to
tackle this problem........ .


Either give your input an ID, change to the document.forms collection:

document.forms['formNAMEnotID'].elements['elementNAMEnot ID'].value;

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 13 '06 #2
k.*********@gma il.com wrote :
Hello all,

In some hidden variable (<input type="hidden" name="hiddenId"
value="test" /> ,i stored some value.I accessed the value "test" using

var id = document.getEle mentById( 'hiddenId' );

It is working fine in IE.
IE incorrectly implements getElementById :

"getElementById : Returns the Element whose ID is given by elementId. If
no such element exists, returns null." DOM 2 Core getElementById
http://www.w3.org/TR/DOM-Level-2-Cor...ml#ID-getElBId and DOM 3
Core getElementById
http://www.w3.org/TR/DOM-Level-3-Cor...ml#ID-getElBId

getElementsByNa me: With [HTML 4.01] documents, this method returns the
(possibly empty) collection of elements whose name value is given by
elementName. DOM 2 HTML getElementsByNa me
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259
But in Mozilla Firefox , null value is returned.
Which is correct per DOM 2 Core.

Is there any way to use hidden variables compatible to browsers......?


var strInputValue = document.forms["FormName"].inputName.valu e;
or
var strInputValue = document.forms["FormName"].elements["inputName"].value;

More on this:
Using Web Standards in Your Web Pages
Accessing Elements with the W3C DOM
How to convert IE-specific ways to access elements into W3C web
standards replacements
http://www.mozilla.org/docs/web-developer/upgrade_2.html# dom_access

For these kinds of issues, check first
Mozilla Web Author FAQ
http://www.mozilla.org/docs/web-developer/faq.html

or the comp.lang.javas cript FAQ first
comp.lang.javas cript FAQ - 8.1 - 2005-11-05
http://jibbering.com/faq/

Gérard
--
remove blah to email me
Jan 13 '06 #3
Thanks for the reply.

I used "id" in hidden variable and its working.
Now i had another problem.
I have an IFrame whose onLoad event calls a javascript. In that script
i used the following to get the hidden variable value(in parent).

var Type = aspxIFrame.pare nt.document.get ElementById("Ty pe");
Here aspxIFrame is the ID of that IFRAME.

This also not working in firefox.

Error: aspxIFrame.pare nt has no properties
Source File: http://192.168.1.12/_layouts/1033/SCRIPT.js
Line: 7

How to solve this problem..?

Thanks,
karthik

Jan 13 '06 #4
VK

k.*********@gma il.com wrote:
I used "id" in hidden variable and its working.
Be aware that it will not work for form submital - only form elements
with "name" attribute set are being submited (though for addressing on
the page you can use either id or name). Also form element labels works
only for id's but not names. So I would suggest to take as a habit to
double identify form elements (but only form elements!).
....
<input name="Data001" id="idData001" >
....
where "data001" will be the name sent to the server, and "iddata001"
will be the id you can use with document.getEle mentById() and <label
for="idData001" acceesskey=hotk ey>

- That's redicilous!
- Totally agree, but that was the price to pay to incorporate modern
DOM stuff into such anscient and legacy heavy thing as HTML form.
var Type = aspxIFrame.pare nt.document.get ElementById("Ty pe");


In iframe:
var Type = self.ownerDocum ent.getElementB yId('idType');

Where hosting page contains:
<input type="hidden" name="Type" id="idType">

P.S. Unless you do not plan/want submit this field to the server, then
<input type="hidden" id="Type">

Jan 13 '06 #5
Once again thanks for the reply.

In IFRAME , i have one aspx page.In that page i show and hide some
elements using

var Toolbar = aspxIFrame.docu ment.getElement ById('ToolbarID ');
if(Toolbar != null)
{
Toolbar.style.v isibility = 'hidden';
}

This is not working in firefox.so i tried something like

var iframeObj = parent.document .getElementById ('aspxIFrame');
if(iframeObj != null)
{
var Toolbar = iframeObj.docum ent.getElementB yId('ToolbarID' );
}

this returns null in IE and no properties error in firefox.

How to get those element by Id..........?

Jan 13 '06 #6
VK

k.karthi...@gma il.com wrote:
Once again thanks for the reply.

In IFRAME , i have one aspx page.In that page i show and hide some
elements using

var Toolbar = aspxIFrame.docu ment.getElement ById('ToolbarID ');
if(Toolbar != null)
{
Toolbar.style.v isibility = 'hidden';
}

This is not working in firefox.so i tried something like

var iframeObj = parent.document .getElementById ('aspxIFrame');
if(iframeObj != null)
{
var Toolbar = iframeObj.docum ent.getElementB yId('ToolbarID' );
}

this returns null in IE and no properties error in firefox.

How to get those element by Id..........?


Sorry I've got lost who's Joe, but it's not your fault.

Just a common answer:

page "MainPage" contains iframe "MyFrame" (so no real frameset, just
MainPage with floating iframe object in it).

To address something in MainPage from within MyFrame:
var foo = self.ownerDocum ent.getElementB yId('bar');

To address something in MyFrame itself from within MyFrame:
var foo = document.getEle mentById('bar') ;
// thus no any extra commands

Jan 13 '06 #7
I am not calling javascript from MyFrame.Instead , i call script in
iframe onLoad().

so document.getEle mentById('bar') ;

gives value if that ID is in MainPage.But i want ID that is in MyFrame.

Jan 13 '06 #8
VK

k.*********@gma il.com wrote:
I am not calling javascript from MyFrame.Instead , i call script in
iframe onLoad().


That is a very bad idea, because how can you predict that by the time
MyPage fired "load" event , MyFrame is ready for scripting too? You
have absolutely no guarantees of that...
Oh wait, is it what you are trying to do? Check is a iframe variable is
available and based on that guess that iframe is loaded? That doesn'r
work anyhow reliable for too many reasons to spell. With frames/iframes
you *have* to go from bottom-to-top: not the main page is asking its
frames, but frames informing the main page.

But as you are the boss of your project, then here is:

from MainPage:
var obj = self.frames["MyFrame"].getReference(" bar");

and in MyFrame (where "MyFrame" is *name*, not id):
function getReference(id ) {
return document.getEle mentById(id);
}
This twisted way is needed to bypass Internet Explorer "same-window
methods scope" rule. Otherwise you can (or can not) get 5011 "Can't
execute code from a freed script" error.

But really sooner or later you'll realize that the only way to do such
things is from bottom-to-up. So why do not accept it right away? ;-)

Jan 13 '06 #9
I cant write Javascript inside MyFrame(aspx displayed in iframe).Those
pages are not in my control.
Depending upon the url i assigned the src of iframe.
Is there any other way.........

Jan 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2434
by: Craig Anderson | last post by:
Can anyone tell me the best way to access a hidden object in a form? I could use a hard-coded index to the elements of the form, but it's too easy to add something before the hidden object and mess up the indexing. For example: The form has a tagid of "myForm" The hidden object has a tagId of "myHiddenObj"
5
3500
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything works fine as it also does in firefox if I call the contents frame directly (i.e. outside of its frameset). However, if I call my main page...
3
1292
by: noor | last post by:
Hi, I'm trying to access Session through java script but its result is negetive. Kindly guid my how can i access session using javascript. plus after accessing it I need to check if that session veriable let suppose (session("FLAG")) contain "ok" then it will change the "class" of a html link. Kindly give a script i'll be thank full to U....
2
4560
by: reynoldlariza | last post by:
Can somebody please help me, i tried playing around with IE6 and Firefox 2.0 browser for setting zIndexes and hide & show of divs. It seems to work to both. I tried repeatedly clicking on different divs on IE and no problem, but on firefox if I do the same, some divs just got hidden without notice. try clicking variably on different divs and it...
0
1735
tolkienarda
by: tolkienarda | last post by:
hi all most of you have seen this form, mostly it has hidden attributes some of which can be changed to select boxes. the part that seems to be a security flaw is that people can edit live html with the web developer toolbar on firefox. i've gone into one of my clients orderforms and bought an expensive item for only five dollars and paypal...
2
2293
by: Zuhaib Hyder | last post by:
please remove double quote error in accessing javascript variable in c# , Page.RegisterStartupScript("MyScript", "<script language=javascript> var thumb = null;thumb = document.getElementById('thumb'); if( thumb && thumb.style.visibility == 'hidden' ) { thumb.style.left = e.pageX ? pageXOffset + e.clientX + 80 : document.body.scrollLeft +...
2
3139
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand...
2
2214
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the pages that used Tab controls. Because it was generated in this way I was able to specify which tab was to be displayed as the "current" tab upon...
0
7724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7944
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8149
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7699
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.