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

Deselecting text in input text box

I have a text input box and I don't want the text to be selected either
when the user tabs to the item or if the user clicks on it.

Now the function below which I found from 2002 in the archive works
fine for IE 6 but it works in neither Netscape 7 nor Firefox 1.0.

I'm hoping some of you might have an alternative suggestion or insight
for Netscape and Firefox.
Code that works in IE6:

function clearSelection () {
if (document.selection)
document.selection.empty();
else if (window.getSelection)
window.getSelection().removeAllRanges();
}

<input type="text" name="theElt" onfocus="javascript: clearSelection()"
size="12" maxlength="20" readOnly style="margin: 7px 3px 0px 3px;
border: 0px;" />

Feb 27 '06 #1
5 2652
VK

le*********@gmail.com wrote:
I have a text input box and I don't want the text to be selected either
when the user tabs to the item or if the user clicks on it.

Now the function below which I found from 2002 in the archive works
fine for IE 6 but it works in neither Netscape 7 nor Firefox 1.0.

I'm hoping some of you might have an alternative suggestion or insight
for Netscape and Firefox.


There was an old exploit by clearing value and by setting it again. I
have no time to check if it's still ticking, sorry:

var fld = document.forms['myForm'].elements['myField'];
var tmp = fld.value;
fld.value = '';
fld.value = tmp;

Feb 27 '06 #2
le*********@gmail.com wrote:
I have a text input box and I don't want the text to be selected either
when the user tabs to the item or if the user clicks on it.
What are you trying to achieve?

It is impossible to reliably prevent either of the above using script.
Making the element readonly will prevent the user from changing the
value using normal keyboard input. Making the element disabled will
knobble it even further, but neither will reliably stop the user from
selecting it or copying the value that's in there.

Now the function below which I found from 2002 in the archive works
fine for IE 6 but it works in neither Netscape 7 nor Firefox 1.0.
It 'works' in IE only in a limited way. Once I've clicked on the input,
or tabbed to it, I can then select the text in it (tab to it then
press Ctrl+A). I can also drag across the input to select it, then copy
and paste into some other application.

If I turn off scripting, the script fails to do anything at all.

I'm hoping some of you might have an alternative suggestion or insight
for Netscape and Firefox.


If you explain what you are trying to achieve, maybe.

[...]
--
Rob
Feb 28 '06 #3
kay
there is one solution, but its not really javascript

here's the code so u get the idea

<div style="width:200px; border:1px solid black; text-align:left">
<div style="width:200px; height:40px; position:relative; top:40px;
background:">&nbsp;</div>
<input type="text" value="value not to be selected" style="width:200px;
height:40px">
</div>

Feb 28 '06 #4
kay wrote:
there is one solution, but its not really javascript
To what?

here's the code so u get the idea
Is your shift key broken?

<div style="width:200px; border:1px solid black; text-align:left">
<div style="width:200px; height:40px; position:relative; top:40px;
background:">&nbsp;</div>
<input type="text" value="value not to be selected" style="width:200px;
height:40px">
</div>


Use tab to navigate to the input, the text is selected, Ctrl+A will copy
it to the clipboard. Triple-click will select it all, as will clicking
in the text then dragging over it. Right-click and choose 'select all'.

How many ways can I defeat thee? :-x
--
Rob
Feb 28 '06 #5
My Internet connection was down for most of last week so I'm just
getting back to this now.

What am I trying to achieve?

I'm trying to make a data entry field that is difficult (but not
necessarily impossible) to edit. I have back-end checks for the
same-ass who is determined to override the value and he'll get an
error.

I don't want a user who tabs through (or clicks on) the field to see it
selected and wonder if it is editable, can be changed, etc. So the
main concern is usuability.

I'm not sure what the functionality of the DIV styles below was. I
don't think that it's changing the highlight colour.

Mar 7 '06 #6

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

Similar topics

1
by: Scott Navarre | last post by:
Hello, I have noticed that when using JavaScript to create a page, the sizes of the text input form elements come out bigger than the size I am trying to set them to. I don't know if it...
2
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I...
8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
3
by: kvnsmnsn | last post by:
I've written the following Javascript file that includes an input text field and an output text field, the latter of which is initialized to zero. Each time the user enters a number in the input...
4
by: backups2007 | last post by:
I want to be able to pass rows of queried data to rows of input text boxes. As the example below shows, I have come up with this incomplete solution. But this code only passes the data to the first...
11
by: Mike Harrison | last post by:
Hi, I have some simple HTML like this: <div id="container" style="width:100%;"> <input type="text" <input type="button" style="float:right;" value="Click here..."> </div> I want the button...
0
by: pazazuzu | last post by:
Hi everyone, I currently have an assignment which I am almost done with but am having problems trying to figure out how to integrate a string function search. I have a text box called...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.