468,754 Members | 1,346 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

I need a "non user-editable" text field

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


Mar 3 '06 #1
7 10006
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.....

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 4 '06 #2
VK

Benton wrote:
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>

Mar 4 '06 #3
Benton wrote:
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?
Mar 4 '06 #4
VK

TheBagbournes wrote:
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) :-)

Mar 4 '06 #5

"Randy Webb" <Hi************@aol.com> escribió en el mensaje
news:d5******************************@comcast.com. ..
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.


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

Mar 4 '06 #6
Benton said the following on 3/4/2006 1:46 PM:
"Randy Webb" <Hi************@aol.com> escribió en el mensaje
news:d5******************************@comcast.com. ..
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.


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;
}
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 4 '06 #7
>>>> 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.

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

Mar 6 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Adrian Parker | last post: by
14 posts views Thread by mirnazim | last post: by
15 posts views Thread by Sander Tekelenburg | last post: by
reply views Thread by Robert Oschler | last post: by
5 posts views Thread by mabond | last post: by
5 posts views Thread by Aneesh Pulukkul[MCSD.Net] | last post: by
1 post views Thread by =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.