textbox values unremoveable until the textbox is clicked - javascript

can anyone help me how to do this? i want to do is the textbox values is removable or cant be change until the textbox is clicked.Can anyone know how to do this?

Add the readonly attribute to your input ...
<input type="text" id="input_a" readonly />
//or
<input type="text" id="input_a" readonly="readonly" />
... and then onClick remove it
document.getElementById('input_a').removeAttribute('readonly');
//or
document.getElementById('input_a').readOnly = false;
The readonly attribute differs from the disabled attribute in that the value is still submitted with the form and, crucially, does not disable click (prevent the event being raised) on the element.

Related

Make readonly fields unclickable

In my form i am using readonly fields.
How to make this readonly fields unclickable I don't want to use disabled fields, just make readonly fields unclickable any one have idea plz share.
You can also use the property disable to make the input unusable and unclickable. I think it's more clear and efficient way.
Here is the the difference between readonly and disable:
<div>
<input disabled type="text">
<input readonly type="text">
<input type="text">
</div>
Call the blur event when input is focused.
<input readonly onfocus="this.blur">
I searched and i found the solution here it is.
<input type="text" readonly="readonly" id="#unclickable" />
<script>
$("#unclickable").focus(function(){
$(this).blur();
});
</script>
I found a much better solution to your problem :)
Assuming you have an input field as :<input type = "text" id = "textfield" >
You need to modify 2 things,
1:
Your HTML declaration should be like :<input type = "text" id = "textfield" readonly>
2:
Go to your css and add the following lines of code
#textfield:hover{
cursor:default;
}
#textfield:focus{
cursor:default;
outline:none;
}
Explanation: It'll still be clickable but we are removing any default style changes happening due to click event to none. i.e. a white border which appears is manually removed. Therefore you can pretty much simulate the effect that nothing is being clicked.

Disable cursor focus for read only textbox while using tab key

I'm using readonly textbox. I want to focus on input textbox only if that is editable. If that is non-editable, How should i disable focus for the particular textbox.
Try this:
<input type="text" value="test" onfocus="this.blur()" readonly="readonly" >
set tabindex = "-1"
and keep one selector css input:read-only {pointer-events: none;}
It's also possible to set the input as disabled which would prevent focusing it and skip it in tab navigation
<input disabled="disabled" />
You can add styles to override the disabled styles

Auto-highlight an input field on focus

I was wondering if there was a way for text inside a input box (pre loaded using value="") to highlight when the user clicks on it?
input type='text' name='url' id='url' value='http://www.a-link.com/' />
EDIT
I need the text to he highlighted so the user can copy it.
<input type="text" name="textbox" value="Test" onclick="this.select()" />
You could attach javascript to the click event to select the text like so:
$(document).ready( function() {
$('#id').click( function( event_details ) {
$(this).select();
});
});
There is a potential issue where the user could be trying to click at a later point in the text to correct a typing mistake and end up selecting the whole thing. A better way would be to trigger this when the input gets focus from the user. you'd replace .click with .focus in the example above.
jQuery event documentation:
http://api.jquery.com/category/events/
Add the following onclick attribute to make the entire <input> automatically highlight when the user clicks on it:
<input type="text" value="Test1" onclick="this.select()" />
Alternatively, if you want the user to be able to change the selection after the initial click, change the onclick attribute to an onfocus attribute. This will also highlight the entire <input> when the user clicks on it, but it allows them to change the highlighted part manually afterwards:
<input type="text" value="Test2" onfocus="this.select()" />
Here is an example of both inputs in action.
You want to use focus property. Like this: http://jsfiddle.net/sCuNs/
html
<p><input type="text" size="40"></p>
css
input:focus, textarea:focus{
background-color: green;
}
Do you mean to select the text?
Use onclick event to fire the code:
document.getElementById("target-input-id").select();
$('#foo').on('mouseup', function(e){
e.preventDefault();
$(this).select();
});
$('#foo').on('mouseup', function(e){
e.preventDefault();
$(this).select();
});
This should do it:
<input type='text' name='url' id='url' onclick="this.select()" value='http://www.a-link.com/' />
<input id="inputField" type="text" size="40" value="text to be highlighted"></p>
document.getElementById('inputField').focus();
The default behavior for focus selects the text in the input field. I was looking for a solution not to do that when I found this.

jQuery selector - input field

I'd like to enable the textbox when it is clicked. However, when I click the textbox, nothing happens. I believe it is a problem with the jQuery selector. Why isn't this working?
<script>
$(document).ready(function() {
$(':input').click(function() {
$(this).removeAttr('disabled');
});
});
</script>
<input type="text" value="123" disabled="disabled" />
Note: I tried both $('input') and $(':input') to select the textfield. Neither worked.
A disabled input isn't going to fire events. Try changing from disabled to readonly.
It has nothing to do with the selector you're using, but rather because, since the input element is disabled, the events for the input will not fire - see: http://www.jsfiddle.net/DvZDh/
<input type="text" value="123" disabled="disabled" />
<input type="text" value="123" />
The code works on the second input element, but not the first. A simple solution would probably be to use CSS to simulate the disabled state instead.

Submitting the value of a disabled input field

I want to disable an input field, but when I submit the form it should still pass the value.
Use case: I am trying to get latitude and longitude from Google Maps and wanna display it, but I don't want the user to edit it.
Is this possible?
I wanna Disable an Input Field on a
form and when i submit the form the
values from the disabled form is not
submitted.
Use Case: i am trying to get Lat Lng
from Google Map and wanna Display it..
but dont want the user to edit it.
You can use the readonly property in your input field
<input type="text" readonly="readonly" />
I know this is old but I just ran into this problem and none of the answers are suitable. nickf's solution works but it requires javascript. The best way is to disable the field and still pass the value is to use a hidden input field to pass the value to the form. For example,
<input type="text" value="22.2222" disabled="disabled" />
<input type="hidden" name="lat" value="22.2222" />
This way the value is passed but the user sees the greyed out field. The readonly attribute does not gray it out.
you can also use the Readonly attribute: the input is not gonna be grayed but it won't be editable
<input type="text" name="lat" value="22.2222" readonly="readonly" />
Input elements have a property called disabled. When the form submits, just run some code like this:
var myInput = document.getElementById('myInput');
myInput.disabled = true;

Categories

Resources