469,290 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Retrieving the value of a readonly text field

Hi all.

I'm not sure why I'm having problems with this but if I try to retrieve the
value of a readonly text form I get back that the object is undefined.

The reason the text is readonly is because it's a date which I set via a
calendar javascript program (associated with a button) only so the user
can't put something silly in requiring validation.

The form send the data correctly when submitted it just doesn't seem to be
able to be read.

I'm sure I'm missing something simple but I can't seem to find it.

Thanks in advance for any help.

All the best,
Tony

Jul 20 '05 #1
7 2426
In article <40**********************@lon-reader.news.telstra.net>,
TC****@elders.com.au enlightened us with...
Hi all.

I'm not sure why I'm having problems with this but if I try to retrieve the
value of a readonly text form I get back that the object is undefined.


If you take your car into a mechanic's, do you tell him or her that it's
broke and then leave?

IOW, post testable code or a URL. :)

--
--
~kaeli~
A little rudeness and disrespect can elevate a meaningless
interaction to a battle of wills and add drama to an
otherwise dull day.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
On Tue, 20 Jan 2004 17:19:12 +1030, Tony Cooke <TC****@elders.com.au>
wrote:
I'm not sure why I'm having problems with this but if I try to retrieve
the value of a readonly text form I get back that the object is
undefined.


Your method of reading the value is obviously at fault. However, without
any snippets of the relevant HTML and JavaScript code, there's no way to
help you properly.

Please give a URL, or a partial copy (showing the relevant areas), of the
page in question.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
> If you take your car into a mechanic's, do you tell him or her that it's
broke and then leave?

IOW, post testable code or a URL. :)

--
--
~kaeli~
A little rudeness and disrespect can elevate a meaningless
interaction to a battle of wills and add drama to an
otherwise dull day.


Hi Kaeli.

Good point... but usually I give a vague indication to the guy or gal then I
leave. I'm no mechanic. :-)

OK. A brief description (ie. vague indication :-)...

Clicking on a button on a form fills in the read only text fields which
contain a date. The reason why they're read only is that I want the user to
click on the button to enter the date and not try and enter it manually
(thus requiring more validation than necessary). The problem is that the
date is mandatory if they select "Yes" to a previous field and I need to
check to see if a date has been entered before allowing them to proceed. I
suppose I could use a hidden field but I believe this should work too.

Here is snippets from the code to look at.

I have a form named "advice" and I have the following within the body of the
HTML.
....
<td class="rowColour1">
&nbsp;Dated:&nbsp;
<input type="text" name="CIRDateDay" id="CIRDateDay" value="" size="2"
readonly="true">/
<input type="text" name="CIRDateMonth" id="CIRDateMonth" value=""
size="2" readonly="true">/
<input type="text" name="CIRDateYear" id="CIRDateYear" value=""
size="4" readonly="true">
<input class="button" type="button" name="CIRDate" id="CIRDate"
value="Calendar" onClick="showCalendar();">
</td>
....

Clicking on the button will bring up the Calendar and from the selection
fill in CIRDateDay, CIRDateMonth & CIRDateYear, each of which is read only.

In the head of the HTML I have the following to check that something is in
there before proceeding to the next page:

....
if ((advice.CIRDateDay.value != "") &&
(advice.CIRDateMonth.value != "") &&
(advice.CIRDateYear.value != "")) {
// Show the values and set OK to advance
alert("1. Day Month Year = >" + advice.CIRDateDay.value + "< >" +
advice.CIRDateMonth.value + "< >" + advice.CIRDateYear.value +"<");
} else {
alert("A date must be entered for when the previous Statement of Advice
was entered.");
}
....

Running this brings back an alert box containing:

1. Day Month Year = >undefined< >undefined< >undefined<

I hope this enough info... oh, and can I have the brakes replaced as I find
it doesn't stop in time and the insurance company is after me. :-)

Thanks Kaeli.

Jul 20 '05 #4
Hi Mike.

I've replied to a previous post by Kaeli with snippets so hopefully that
helps.

Thanks for your reply.

All the best,
Tony
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Tue, 20 Jan 2004 17:19:12 +1030, Tony Cooke <TC****@elders.com.au>
wrote:
I'm not sure why I'm having problems with this but if I try to retrieve
the value of a readonly text form I get back that the object is
undefined.


Your method of reading the value is obviously at fault. However, without
any snippets of the relevant HTML and JavaScript code, there's no way to
help you properly.

Please give a URL, or a partial copy (showing the relevant areas), of the
page in question.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #5
On Wed, 21 Jan 2004 09:38:26 +1030, Tony Cooke <TC****@elders.com.au>
wrote:

<snip>
<td class="rowColour1">
&nbsp;Dated:&nbsp;
<input type="text" name="CIRDateDay" id="CIRDateDay" value=""
size="2"
readonly="true">/
<input type="text" name="CIRDateMonth" id="CIRDateMonth" value=""
size="2" readonly="true">/
<input type="text" name="CIRDateYear" id="CIRDateYear" value=""
size="4" readonly="true">
<input class="button" type="button" name="CIRDate" id="CIRDate"
value="Calendar" onClick="showCalendar();">
</td>
...

Clicking on the button will bring up the Calendar and from the selection
fill in CIRDateDay, CIRDateMonth & CIRDateYear, each of which is read
only.

In the head of the HTML I have the following to check that something is
in there before proceeding to the next page:

...
if ((advice.CIRDateDay.value != "") &&
(advice.CIRDateMonth.value != "") &&
(advice.CIRDateYear.value != "")) {
// Show the values and set OK to advance
alert("1. Day Month Year = >" + advice.CIRDateDay.value + "< >" +
advice.CIRDateMonth.value + "< >" + advice.CIRDateYear.value +"<");
} else {
alert("A date must be entered for when the previous Statement of
Advice
was entered.");
}


Odd, because the values are displayed properly in IE 6 (Win) and Opera
7.23 (Win). May I ask what browser you are using?

The only explanation that I could give at the moment is that some browsers
don't accept the shortcut method[1] when id attributes are used.

Try using the collection method[2] to access the form controls. Near the
beginning of the code snippet above, add (for later simplicity):

var adviceForm = document.forms['advice'];

Then access the form controls like this:

if(( adviceForm.elements['CIRDateDay'].value != '' ) &&
...

I can't guarantee that that will work, but give it a shot.

Good luck,
Mike

[1] For example,
document.formName.formControl.value

[2] For example,
document.forms['formName'].elements['formControl'].value

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6
Hi Mike.

Bit late over there isn't it... or don't you have work tomorrow (today?).
Odd, because the values are displayed properly in IE 6 (Win) and Opera
7.23 (Win). May I ask what browser you are using?
I'm using IE 6 SP1.
I can't guarantee that that will work, but give it a shot.
Gave it a shot but it didn't seem to work. Same error.
Good luck,
Mike
I need it. :-)
[1] For example,
document.formName.formControl.value

[2] For example,
document.forms['formName'].elements['formControl'].value


Thanks anyway. I may try making them not readonly before the check then
turning them back to readonly after.

Thanks again Mike.

All the best,
Tony
Jul 20 '05 #7
OK Mike, I think I've just taken out the "Idiot of the Year" award.

I've used the calendar somewhere else and copied the fields for the date
(day, month, year) to the other area.

I've changed the name= part in the other area but not the id= part. So I had
2 fields with the same id.

Changed them to be different and now all is OK.

Sorry to have wasted your time. Thanks for your help though.

All the best,
Tony
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by crjunk | last post: by
2 posts views Thread by 4Ankit | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.