473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

disabling form elements in IE

I need to disable/enable form elements in my form.
the code i was developed works fine in FF, but in IE, its behaviour is
very strange!!

in the form, we have a lot of checkboxes, all of them named like
"xyz_np".
in front of each checkbox, we have some fields, named "xyz"

this is my JS code.
after clicking on checkboxes:
=============== =============== ========
function clicked(me, objNames){
obj = findObj(me);
for(i = 0; i < objNames.length ; i++){
obj1 = findObj(objName s[i]);
if(obj.checked= =true){
obj1.disabled = false;
obj1.style.bord er = "1px solid #000";
obj1.style.colo r = "#000000";
}else{
obj1.disabled = true;
obj1.style.bord er = "1px solid lightgray";
obj1.style.colo r = "gray";
}
}
}
=============== =============== =========
at startup, on body onload event:
=============== =============== =========
function start(){
obj = findObj("search ");
for(i = 0; i < obj.elements.le ngth; i++){
if(obj.elements[i].name.indexOf(' _np')==-1 &&
obj.elements[i].name.indexOf(' submit')==-1){
obj.elements[i].disabled = true;
obj.elements[i].style.border = "1px solid lightgray";
obj.elements[i].style.color = "gray";
}
}
}

NOTE: findObj() is Macromedia findObj function. it should return an
element resource.

this code, in IE, cannot disable a field **UNTIL** you typed some
characters in that field, before disabling!!!!

i used FF1.5b2 and IE6SP1.

Oct 28 '05 #1
4 2267
omidmottaghi wrote:
function clicked(me, objNames){
obj = findObj(me);
for(i = 0; i < objNames.length ; i++){
Better (because of the declaration) and more efficient (because of the
decrement) is

for (var i = objNames.length ; i--;)
{

You also want to test whether findObj() [or its equivalent] returned
a reference to an appropriate object before you apply the property
accessor syntax to that value. That would be at least

var obj = ...;
if (obj)
{
...
}
obj1 = findObj(objName s[i]);
if(obj.checked= =true){
obj1.disabled = false;
Same here.
obj1.style.bord er = "1px solid #000";
obj1.style.colo r = "#000000";
Why not be consequent (in supporting low color depths) and write

obj1.style.colo r = "#000";

instead?
[...]
function start(){
obj = findObj("search ");
for(i = 0; i < obj.elements.le ngth; i++){
See above.
if(obj.elements[i].name.indexOf(' _np')==-1 &&
obj.elements[i].name.indexOf(' submit')==-1){
Such unnecessary applications of the property accessor syntax
(short and informal: "lookup operations") should be avoided:

for (var el = obj.elements, i = el.length; i--;)
{
var o = el[i];
if (o.name
&& o.name.indexOf( '_np') == -1
&& o.name.indexOf( 'submit') == -1)
{
// contains references to o
}
}
obj.elements[i].disabled = true;
Try

if (!(o.disabled = true))
{
o.disabled = "disabled";
}
obj.elements[i].style.border = "1px solid lightgray";
obj.elements[i].style.color = "gray";
You may be looking for `backgroundColo r', not `color'. Furthermore, you
probably want to set both `color' and `backgroundColo r' at the same time:
<http://www.w3.org/QA/Tips/color>.
[...]
NOTE: findObj() is Macromedia findObj function. it should return an
element resource.
It should not be used at all. The last time I checked, like
any of Macromedia's JS code I have seen to date, it was junk.
this code, in IE, cannot disable a field **UNTIL** you typed some
characters in that field, before disabling!!!!
If that is true and cannot be blamed on any line of code you used, then it
is an IE bug and you cannot do anything about it (except work around it or
not recommend [this specific] IE [version] for use).
i used FF1.5b2 and IE6SP1.

PointedEars

P.S.: Do not use tabs for indentation, use spaces.
P.P.S.: Your Exclamation Mark key appears to be broken.
Oct 28 '05 #2
Thanks PointedEars :)

the last code i used is, before your reply:
=============== ============
function findObj(theObj)
{
return foundObj = document.getEle mentById(theObj );
}

function clicked(me, objNames){
obj = findObj(me);
for(i = 0; i < objNames.length ; i++){
obj1 = findObj(objName s[i]);
if(obj.checked= =true){
obj1.disabled = false;
obj1.style.colo r = "#000";
obj1.style.back groundColor = "#fff";

}else{
obj1.disabled = true;
obj1.style.colo r = "#888";
obj1.style.back groundColor = "#EEE";
}
}
}

function start(){
obj = findObj("search ");
for(i = 0; i < obj.elements.le ngth; i++){
if(obj.elements[i].name.indexOf(' _np')==-1 &&
obj.elements[i].name.indexOf(' submit')==-1){
obj.elements[i].disabled = true;
}
}
}
=============== ============

and this code works fine in IE! (not enough fine as it must!)
but i forced to add css styles in tags, instead of javascript, because
IE first do JS, then apply CSS settings except ONLY FIRST field.

i think i should remove "start()" function at all and add
"disabled="disa bled"" to each tag.

AND i will add some of your NICE sugestions :)

Thanks, Omid

P.S.S: no :P

Oct 28 '05 #3
omidmottaghi wrote:
the last code i used is, before your reply:
=============== ============
function findObj(theObj)
{
return foundObj = document.getEle mentById(theObj );
}
That method is entirely redundant. It would only not be if it included
the required feature test for the implementation of the used DOM Level 2
method. The assignment to `foundObj' is, if `foundObj' is even accessed
outside of the method, bad style: it defines, but not declares, a new
global variable from local scope.

So it should read more like:

function findObj(theObj)
{
var t;
if ((t = typeof document.getEle mentById) == "function"
|| t == "object" && document.getEle mentById)
{
return document.getEle mentById(theObj );
}

return null;
}

the return value of this method would have to be evaluated (instead of
using `foundObj') after calling it then.
and this code works fine in IE! (not enough fine as it must!)
*Maybe*. How many different IE versions on how many different
platforms and operating systems have you tested with?
but i forced to add css styles in tags, instead of javascript, because
IE first do JS, then apply CSS settings except ONLY FIRST field.
Are you sure about that and that you really understood how the CSS cascade
works?
i think i should remove "start()" function at all and add
"disabled="disa bled"" to each tag.
I think you should consume more tea[tm] before you start coding.
AND i will add some of your NICE sugestions :)


:)
PointedEars
Oct 28 '05 #4
Thanks, i will fix findObj later.
*Maybe*. How many different IE versions on how many different
platforms and operating systems have you tested with? Maybe :)
i tested it with 2-3 IE versions.
Are you sure about that and that you really understood how the CSS cascade
works?

yes, as i told, i have a lot of fields, all of them had same CSS code
and same JS code. but JS code ONLY applied to first field and CSS code
applied to other fields. (be sure im right :) )

Thanks again PointerEars :)

Oct 30 '05 #5

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

Similar topics

3
1486
by: Perttu Pulkkinen | last post by:
What si the best and MOST BROWSERCOMPATIBLE way of making elements disabled for the user? Also considering different kind of elements: textfields, selects, radiobuttons and textareas. This is what I have had, its quite okay in IE but not good enough for Netscape. - I remember there was problem with setAttribute(wich would looked natural pair to removeAttribute) so I used disabled = "disabled" instead. function bluron(form,ele)
1
1807
by: Jason Galvin | last post by:
I would like to disable the auto-populating feature (remembers form element text between post-backs) when creating a .NET form. I have succeeded in disabling auto-populate by creating my controls during PreRender, but that becomes highly cumbersome. Is there a way to explicitly turn off auto-populate? I'm pretty sure the form isn't getting auto-populated by the ViewState mechanism, because I've specifically set EnableViewState to...
3
33111
by: John Dalberg | last post by:
I have a webpage with a form. Depending on user selections at the top of the page, the page will disable sections of the form. My plan is to put each section between a <div></div>. Each section contains some collection of form elements. So if the user does not select some criteria, the related section of the form gets disabled. In a typical Windows type of application these elements get disabled and greyed out. What's the best way to do...
2
6317
by: dougawells | last post by:
Hi- I'm wanting to have a set of radio buttons disabled when a form is displayed, then if they check another specific radio button, those would become enabled. I've tried setting it via window.document.formname.radiogroup.disabled="true"; (or false) - but that doesn't seem to work. I've seen this done with text boxes, but not with radio buttons. Can anyone give any help? Thanks
11
2241
by: shankwheat | last post by:
I have a function which passes text from txtdebt to debtsbox which works fine. However, I want to add code which examines the value of debtsbox and if any of the values the user entered contain the string "d" then I want to emable rblDebts which is disabled when the page loads. This part is not working (no errors) and I'm not sure why. Thanks. <script type="text/javascript" language="JavaScript"> <!-- Begin oldvalue = "";
3
3481
by: Sonnich | last post by:
Hi all! Say, I have <buttonor <input type="submit">, how do then disable them once they are clicked? I could not find the right thing on the net :-( S
1
1292
by: gubbachchi | last post by:
Hi all, I have an issue here. There is a link "My plan" in the php page1. On clicking this link directs to a form which has some entries that has to be filled by the user.And once the user fills the form and clicks the submit button the entries will be stored in the database. What I need is, when the user fills the form and submits the form once all the form elements should be disabled. If the user again clicks the "My plan" link, the...
0
9639
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9939
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6729
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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

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.