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

Determine Input Box Property

I have a script that I want to run only when my input box IS NOT
disabled. Can someone tell me if something is wrong with my script? Is
"disabled" the correct property to use?

function TextChanged(i){
if (!document.ScheduleForm["txtGrossPayroll" + i].disabled) {
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
}
Thanks,
CR Junk

Sep 9 '05 #1
10 1959
Ivo
"crjunk" wrote
I have a script that I want to run only when my input box IS NOT
disabled. Can someone tell me if something is wrong with my script? Is
"disabled" the correct property to use?

function TextChanged(i){
if (!document.ScheduleForm["txtGrossPayroll" + i].disabled) {
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
}


Looks good to me. Not happy with how it runs? Just nitpicking, but the
two lookups into the txtRecordStatus element could be handled more
efficiently by storing it in a temporary variable:

function TextChanged(i){
var sf = document.forms.ScheduleForm.elements;
if ( !sf["txtGrossPayroll" + i].disabled ) {
var rs = sf.txtRecordStatus;
rs.value = "Changes Made; Record Not Saved.";
rs.style.color = "#FF0000";
}
}

hth
ivo


Sep 9 '05 #2
ivo wrote
Just nitpicking, but the two lookups into the txtRecordStatus element could be handled more efficiently by storing it in a temporary variable


Thanks for the information on using a temporary variable.

I found a mistake that I used. Instead of disabled, I have the input
set as readonly - therefore the formula should be :
if (!document.ScheduleForm["txtGr*ossPayroll" + i].readonly)

Does using readonly make any difference?

Thanks,
CR Junk

Sep 9 '05 #3
Ivo
"crjunk" wrote
Instead of disabled, I have the input
set as readonly - therefore the formula should be :
if (!document.ScheduleForm["txtGr*ossPayroll" + i].readonly)

Does using readonly make any difference?


None at all, but note that the DOM properties are case-sensitive and
"readOnly" features a capital O.

A link (watch for wrap):
http://msdn.microsoft.com/workshop/a...erties/readonl
y_1.asp

chrs
ivo

Sep 9 '05 #4
crjunk a écrit :
I have a script that I want to run only when my input box IS NOT
disabled. Can someone tell me if something is wrong with my script? Is
"disabled" the correct property to use?

function TextChanged(i){
if (!document.ScheduleForm["txtGrossPayroll" + i].disabled) {
if (!document.ScheduleForm.elements.namedItem("txtGro ssPayroll +
i).disabled) {
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
}
Thanks,
CR Junk


Using Web standards ... on accessing for elements:
http://www.mozilla.org/docs/web-deve...tml#dom_access

Gérard
--
remove blah to email me
Sep 10 '05 #5
Gérard Talbot a écrit :
function TextChanged(i){
if (!document.ScheduleForm["txtGrossPayroll" + i].disabled) {


oops

if (!document.ScheduleForm.elements.namedItem("txtGro ssPayroll" +
i).disabled) {

rather

Using Web standards ... on accessing for elements:
http://www.mozilla.org/docs/web-deve...tml#dom_access


Gérard
--
remove blah to email me
Sep 10 '05 #6
Gérard Talbot said the following on 9/9/2005 9:52 PM:
crjunk a écrit :
I have a script that I want to run only when my input box IS NOT
disabled. Can someone tell me if something is wrong with my script? Is
"disabled" the correct property to use?

function TextChanged(i){
if (!document.ScheduleForm["txtGrossPayroll" + i].disabled) {

if (!document.ScheduleForm.elements.namedItem("txtGro ssPayroll +
i).disabled) {


Forms are a collection, and as such, should be accessed via the Array
syntax - []. So, the original code ...["txt...]. was correct. Using ()
for form elements is an IE only way of accessing them.
document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
Saved.";
document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
}
}
Thanks,
CR Junk


Using Web standards ... on accessing for elements:
http://www.mozilla.org/docs/web-deve...tml#dom_access


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 10 '05 #7
<snip>Instead of disabled, I have the input set as readonly.
<snip>Does using readonly make any difference?

Yes, the browser should not send the name/value pair for a disabled
form element. It would send it for a read only element.

Sep 11 '05 #8
Randy Webb wrote:
Gérard Talbot said the following on 9/9/2005 9:52 PM:
crjunk a écrit :
I have a script that I want to run only when my input
box IS NOT disabled. Can someone tell me if something
is wrong with my script? Is "disabled" the correct
property to use?

function TextChanged(i){
if (!document.ScheduleForm["txtGrossPayroll" + i].disabled) {

if (!document.ScheduleForm.elements.namedItem(
"txtGrossPayroll + i).disabled) {


Forms are a collection, and as such, should be accessed via
the Array syntax - [].


Well, they should be accessed with property accessors. Bracket notation
is only necessary when the names used do not qualify as Identifiers.
Though bracket notation is recommended for the task regardless of the
names in order to highlight the distinction between names originating
within JS and the DOM and names that originate in mark-up elements, and
to conform with the W3C HTML DOM standard (as explained below).
So, the original code ...["txt...]. was correct.
Functional, yes. Correct is more a matter of opinion. I would quibble
about the use of the 'shortcut' of referencing the form object as a
named property of the document. Because while no HTML DOM has been
identified as not making forms available as properties of the document
we know that some XHTML DOMs only support the W3C HTML DOM standard
method of accessing forms as properties of the - document.forms -
collection, and using the - document.forms - collection works on all
browsers that allow the 'shortcut'. This makes the W3C DOM standard
property accessors the most widely supported and general approach (being
equally viable in all environments that expose forms to scripting, past
present and (theoretically) future).
Using ()
for form elements is an IE only way of accessing them.

<snip>

It is, but that is not relevant here as the function being called is
the - namedItem - method defined as a method of the HTMLCollection
interface in the W3C DOM standard. The problem with the use of this
method is that the older browsers providing pre-W3C HTML DOM access to
forms do not necessarily implement the - namedItem - method. That is not
actually an issue when writing ECMAScritp because the ECMAScript
bindings for the HTMl DOM says:-

<quote cite="http://www.w3.org/TR/2003/
REC-DOM-Level-2-HTML-20030109/ecma-script-binding.html">

Functions of objects that implement the HTMLCollection interface:

item(index)

This function returns an object that implements the Node
interface.

The index parameter is a Number.

Note: This object can also be dereferenced using square
bracket notation (e.g. obj[1]). Dereferencing with an integer
index is equivalent to invoking the item function with that
index.
namedItem(name)

This function returns an object that implements the Node
interface.

The name parameter is a String.

Note: This object can also be dereferenced using square
bracket notation (e.g. obj["foo"]). Dereferencing using a
string index is equivalent to invoking the namedItem function
with that index.
</quote>

And so because the specification requires that the - item - and -
namedItem - methods are effectively mapped to bracket notation property
accessors there is never any need to use the methods directly, and so no
reason to limit cross-browser compatibility through their use. A fully
W3C HTML DOM standard conforming property accessor for the form control
would go:-

document.forms['ScheduleForm'].elements[("txtGrossPayroll + i)]

- and still be fully functional with all of the browsers that have ever
exposed forms to javascript (and, because it is HTML DOM standard, can
reasonably be expected to be equally functional on future HTML DOM
standard browsers).

Richard.
Sep 11 '05 #9
Richard Cornford wrote:
<snip>
... . A fully W3C HTML DOM standard conforming property
accessor for the form control would go:-

document.forms['ScheduleForm'].elements[("txtGrossPayroll + i)]

<snip>

Except for the missing quote mark in the concatenation expression.
Should be:-

document.forms['ScheduleForm'].elements[('txtGrossPayroll' + i)]

Richard.
Sep 11 '05 #10
I determined that part of my problem was that I originally used
disabled when I should have used readOnly. The other mistake that I
made was that I used readonly instead of readOnly. I was not aware
that the property was case-sensitive.

CR Junk

Sep 12 '05 #11

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

Similar topics

3
by: mikeorb | last post by:
Is there a way to determine the object that a property is in? For example: function MyClass() { ... } MyClass.prototype.myFunc = function() { ... } var obj = new MyClass(); var sameobj =...
3
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image"...
1
by: Chris Ashley | last post by:
I'm trying to use a treeview control for navigation in an app. How do I determine which node has been selected? I can't use the text property because some nodes have the same name, and the index...
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
2
by: Frank | last post by:
I created this test routine to return the form containing a certain input element: function GetElementForm(element) { // Return the form that contains element. var myElement = element; ...
10
by: rh0dium | last post by:
Hi all, Below is a basic threading program. The basic I idea is that I have a function which needs to be run using a queue of data. Early on I specified my function needed to only accept basic...
3
by: Maverick | last post by:
Hi, I have to give a browse button and you will be able to browse and pick the image path instead of typing it out. One more requirement will be the image will be residing on a shared machine in...
10
by: John Brown | last post by:
Hi there, Does anyone know how to (generically) determine the currently active form for an application using a "static" function (so I can call it from anywhere). There is no offiical way I've...
7
by: Ralf Jansen | last post by:
For logging purposes i want to determine if the current executing code is running in an ~exceptionhandling context~. I need no details about the exception just if an exception has been thrown and...
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: 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
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
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...
0
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...

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.