I need a "non user-editable" text field

B

Benton

Hi there,

I have a text box which will receive its value from a pop-up date picker.
The user should not be able to edit this field with the keyboard or mouse.

I am using ASP.NET. If I set the readonly property of the textbox to true,
it won't let the user change it and it can receive its value from the pop-op
calendar, just what I need. Problem is, after a postback, value is lost.

So I think Javascript may come to the rescue here. Is there a way to make a
field "non user-editable" without setting the "readonly" attribute? Maybe a
trick to make the field reject focus?

Many thanks in advance,

-Benton
 
R

Randy Webb

Benton said the following on 3/3/2006 6:15 PM:
Hi there,

I have a text box which will receive its value from a pop-up date picker.
The user should not be able to edit this field with the keyboard or mouse.

Then use a hidden field.
I am using ASP.NET.
Irrelevant.

If I set the readonly property of the textbox to true, it won't let the
user change it and it can receive its value from the pop-op calendar, just
what I need. Problem is, after a postback, value is lost.

Then use a hidden field.
So I think Javascript may come to the rescue here. Is there a way to make a
field "non user-editable" without setting the "readonly" attribute? Maybe a
trick to make the field reject focus?

Use a hidden field.....
 
V

VK

Benton said:
Hi there,

I have a text box which will receive its value from a pop-up date picker.
The user should not be able to edit this field with the keyboard or mouse.

I am using ASP.NET. If I set the readonly property of the textbox to true,
it won't let the user change it and it can receive its value from the pop-op
calendar, just what I need. Problem is, after a postback, value is lost.

So I think Javascript may come to the rescue here. Is there a way to make a
field "non user-editable" without setting the "readonly" attribute? Maybe a
trick to make the field reject focus?

As suggested use hidden field to store the actual value. Use a DHTML
widget to display non-editable (but still selectable) data. Make you
date widget to set both hidden field value and innerHTML value of
pseudo-input. Something like:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
..inputText {
font: 0.8em Tahoma,Geneva, sans-serif;
margin: 5px 5px;
padding: 2px 2px;
width: 20ex;
height: auto}

..pseudoInput {
display: -moz-inline-box;
display: inline-block;
font: 0.8em Tahoma, Geneva, sans-serif;
width: 20ex;
height: auto;
margin: 5px 5px;
padding: 1px 2px;
border: thin inset}
</style>
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
<fieldset>
<legend>Test</legend>
<input type="text" name="txt" value="01.01.1970" class="inputText">
<span id="dateView" class="pseudoInput">01.01.1970</span>
<input type="hidden" name="date">
</fieldset>
</form>

</body>
</html>
 
T

TheBagbournes

Benton said:
Is there a way to make a
field "non user-editable" without setting the "readonly" attribute?

Why would you need to? What's wrong with the readonly attribute?
 
V

VK

TheBagbournes said:
What's wrong with the readonly attribute?

Asome. There is nothing wrong with it.

There is something wrong with people not reading docs through
(shamefully pointing to myself) :)
 
B

Benton

Then use a hidden field.

Please excuse my newbiness but if the field is not visible, the the user
would not get any feedback on the value returned by the date picker. Sure I
am missing something.

Regards,

-Benton
 
R

Randy Webb

Benton said the following on 3/4/2006 1:46 PM:
Please excuse my newbiness but if the field is not visible, the the user
would not get any feedback on the value returned by the date picker. Sure I
am missing something.

You say you are using a popup date picker. Fine. When the date picker
puts the value in the text field then you also have it put it in a span
element to display it to the user. Then, the user gets feedback, they
can't change it, and your hidden field gets the value. You could even
style the span to *look* like an input field.

Without seeing your date picker, and how it sets the hidden field, I can
only guess at how to tell you to do the above though. The simplest way
might be for the date picker to call a function in the opener window
that would set it:

opener.setDateValue(dateValueFromPicker);

And then in the opener:

function setDateValue(dateValue){
document.forms['formID'].elements['hiddenFieldName'].value = dateValue;
document.getElementById('spanID').innerHTML = dateValue;
}
 
B

Benton

I have a text box which will receive its value from a pop-up date
You say you are using a popup date picker. Fine. When the date picker puts
the value in the text field then you also have it put it in a span element
to display it to the user. Then, the user gets feedback, they can't change
it, and your hidden field gets the value. You could even style the span to
*look* like an input field.

It works beautifully. Thanks to all of you guys for your help.

Regards,

-Benton
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top