Retrieving the value of a readonly text field

T

Tony Cooke

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
 
K

kaeli

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
 
M

Michael Winter

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
 
T

Tony Cooke

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.
 
T

Tony Cooke

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
 
M

Michael Winter

<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
 
T

Tony Cooke

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
 
T

Tony Cooke

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top