473,654 Members | 3,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disabling Form Elements

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="JavaS cript">
<!-- Begin
oldvalue = "";
function passText(passed value) {
if (passedvalue != "") {
var totalvalue = passedvalue+"\n "+oldvalue;
document.form1. debtsbox.value = totalvalue;
oldvalue = document.form1. debtsbox.value;
}

var searchfor = "d";
if (oldvalue.searc h(searchfor) -1) {
document.form1. rblDebts.disabl ed = false;
} else
document.form1. rblDebts.disabl ed = true;
}
// End -->
</script>

<form id="form1">
Debt ID: <input type="text" name="txtdebt" maxlength="5" />
<input type="button" value="Add to list" class="buttonst yle2"
onClick="passTe xt(this.form.tx tdebt.value);">

Debts added to your list:
<textarea cols="40" rows="5" name="debtsbox" ></textarea>

<input type="radio" id="rblDebts" disabled="true" >

</form>

Oct 17 '06 #1
11 2234

"shankwheat " <ev*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
<input type="radio" id="rblDebts" disabled="true" >
One radio button makes no sense.

http://www.w3.org/TR/1999/REC-html40...rms.html#radio

nf
Oct 17 '06 #2
Right..Adding a bunch of radio buttons wasn't relevant to my question.
What is important is that it's a form element.
nutso fasst wrote:
"shankwheat " <ev*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
<input type="radio" id="rblDebts" disabled="true" >

One radio button makes no sense.

http://www.w3.org/TR/1999/REC-html40...rms.html#radio

nf
Oct 17 '06 #3

"shankwheat " <ev*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Right..Adding a bunch of radio buttons wasn't relevant to my question.
What is important is that it's a form element.
Ah, but in that case, doesn't rblDebts represent an array of form elements?
You can't disable an array. Try
document.form1. rblDebts[0].disabled = false
and see what happens.

nf
Oct 17 '06 #4

"nutso fasst" <no********@no. wherewrote in message
news:QJ******** *******@newssvr 14.news.prodigy .com...
>
"shankwheat " <ev*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Right..Adding a bunch of radio buttons wasn't relevant to my question.
What is important is that it's a form element.

Ah, but in that case, doesn't rblDebts represent an array of form
elements?
You can't disable an array. Try
document.form1. rblDebts[0].disabled = false
and see what happens.

nf
Oh, and one other thing. Your form element needs a name before you can refer
to it as document.form1:

<form name="form1">

Using id, you'd need to refer to it by id, e.g.:

document.getEle mentById('form1 ').rblDebts[0].disabled = false

nf
Oct 17 '06 #5
shankwheat wrote:

[snip]
>
<input type="radio" id="rblDebts" disabled="true" >
<input type="radio" id="rblDebts" disabled>

OR

<input type="radio" id="rblDebts" disabled="disab led" />

Mick.

>
</form>
Oct 18 '06 #6
nutso fasst wrote:
"nutso fasst" <no********@no. wherewrote in message
news:QJ******** *******@newssvr 14.news.prodigy .com...

"shankwheat " <ev*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Right..Adding a bunch of radio buttons wasn't relevant to my question.
What is important is that it's a form element.
Ah, but in that case, doesn't rblDebts represent an array of form
elements?
No, it is an HTMLCollection of form controls:

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-75708506 >

which has some similarities to an array, but is generally very
different.

You can't disable an array.
Quite correct, but it isn't an array. Some browsers support disabling
all the controls in a form by setting a disabled attribute for the form
element, but it's not part of the W3C standard and is not widely
supported.

Try document.form1. rblDebts[0].disabled = false
and see what happens.

nf
Oh, and one other thing. Your form element needs a name before you can refer
to it as document.form1:

<form name="form1">

Using id, you'd need to refer to it by id, e.g.:

document.getEle mentById('form1 ').rblDebts[0].disabled = false
Not at all - in modern browsers either name or ID will do when using
the forms collection. Keep using names if old browsers need to be
supported. If an ID is used, the syntax must be:

document.forms. form1.rblDebts

which works for names too.
--
Rob

Oct 19 '06 #7

"RobG" <rg***@iinet.ne t.auwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
No, it is an HTMLCollection of form controls:

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-75708506 >

which has some similarities to an array, but is generally very
different.
I appreciate exegesis, Rob, but in this I'm dubious. If it were an
HTMLCollection it would have a namedItem method, and how can that be when
all nodes have the same name? In any case, relative to the OP's need to
access attributes, a list of nodes and an array are not at all different.
Using id, you'd need to refer to it by id, e.g.:

document.getEle mentById('form1 ').rblDebts[0].disabled = false

Not at all - in modern browsers either name or ID will do when using
the forms collection. Keep using names if old browsers need to be
supported. If an ID is used, the syntax must be:

document.forms. form1.rblDebts

which works for names too.
And so is clearly superior syntax, thank you. But it's not how the syntax
"must be" when the form element has an ID.
document.getEle mentById('form1 ').rblDebts also works in modern browsers.

In the OP's example the form had ID="form1" but his script referred to
document.form1. rblDebts, which is not correct syntax and will not work in
modern browsers.

nf
Oct 19 '06 #8
ASM
nutso fasst a écrit :
> document.forms. form1.rblDebts

which works for names too.

And so is clearly superior syntax, thank you. But it's not how the syntax
"must be" when the form element has an ID.
Usualy each element of a form has a name ... !
document.getEle mentById('form1 ').rblDebts also works in modern browsers.
If and *only* if 'form1' is really an id
(IE understanding name and id are same)
and if 'rblDebts' is itself a name (and not an id)
In the OP's example the form had ID="form1" but his script referred to
document.form1. rblDebts, which is not correct syntax and will not work in
modern browsers.
Right.
Oct 19 '06 #9
nutso fasst wrote:
"RobG" <rg***@iinet.ne t.auwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
No, it is an HTMLCollection of form controls:

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-75708506 >

which has some similarities to an array, but is generally very
different.

I appreciate exegesis, Rob
exegesis: critical explanation or interpretation of a text or portion
of a text, esp. of the Bible.
<URL: http://dictionary.reference.com/browse/exegesis >
>, but in this I'm dubious.
You should be certain that it isn't a javascript Array at least. :-)
If it were an HTMLCollection it would have a namedItem method,
and how can that be when all nodes have the same name?
That logic isn't particularly convincing, did you test it? The object
returned by using dot property access to a set of radio buttons does in
fact have a namedItem method in IE, but not Firefox.

Firefox doesn't implement the namedItem method for forms either, but I
don't think you'd deduce from that that a form isn't a dinky-di
HTMLForm. :-)
In any case, relative to the OP's need to access attributes, a list of
nodes and an array are not at all different.
That is about the only feature that they share, along with a
self-adjusting length property. Some people have come here wondering
why such "arrays" don't behave when asked to pop(), slice(), shift(),
etc.

HTML collections are *always* contiguous and start from zero, from
which can be deduced that if there is no item(0) (i.e. it is undefined)
then the length *must* be zero and also that you can't add an item
beyond an index equal to the length - neither of which is necessarily
true for an Array.
Using id, you'd need to refer to it by id, e.g.:
>
document.getEle mentById('form1 ').rblDebts[0].disabled = false
Not at all - in modern browsers either name or ID will do when using
the forms collection. Keep using names if old browsers need to be
supported. If an ID is used, the syntax must be:

document.forms. form1.rblDebts

which works for names too.

And so is clearly superior syntax, thank you. But it's not how the syntax
"must be" when the form element has an ID.
document.getEle mentById('form1 ').rblDebts also works in modern browsers.
The point was in regard to dot property access to the forms collection
using IDs. Where a name is used instead of, or in addition to, an ID
the syntax can be as the OP wrote.
In the OP's example the form had ID="form1" but his script referred to
document.form1. rblDebts, which is not correct syntax and will not work in
modern browsers.
Which is why I pointed out the correct syntax to use with IDs. It is
generally recommended to use the relevant collection, rather than
getElementById, when accessing forms and their controls.
--
Rob

Oct 19 '06 #10

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

Similar topics

3
1476
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)
4
2262
by: omidmottaghi | last post by:
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:
1
1803
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
33105
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
6303
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
3
3475
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
1278
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
8379
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
8294
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
8816
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
8709
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
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
7309
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
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1597
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.