LyndonOHRC
Programmer
I am giving focus to an input element but also want to select all the text that it contains so the user can easily replace it with a new value.
Giving focus works fine but the select() method doesn't seem to work. No text ever gets selected.
I've tested in IE 11 and Firefox 27.0.1 with same result.
I've tried:
Also tried:
Also tried:
Nothing seems to work. Any help appreciated
Complete document:
Lyndon
---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
Giving focus works fine but the select() method doesn't seem to work. No text ever gets selected.
I've tested in IE 11 and Firefox 27.0.1 with same result.
I've tried:
Code:
document.getElementById('RanchNameSearchString').focus();
document.getElementById('RanchNameSearchString').select();
Code:
$('#RanchNameSearchString').focus(function () {
$('#RanchNameSearchString').select();
});
Code:
$('#RanchNameSearchString').focus();
$('#RanchNameSearchString').select();
Nothing seems to work. Any help appreciated
Complete document:
Code:
<html>
<head>
<meta charset="utf-8" />
<title>Ranch Lookup</title>
<link rel="stylesheet" type="text/css" href="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">[/URL]
<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>[/URL]
<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>[/URL]
<script>
$(document).ready(function(){
var getDocumentBackgroundColor='White';
$("#RanchNameDataInput, #OwnerLastNameDataInput").hide();
$("#menuRow").css("background-color",getDocumentBackgroundColor);
$("#ZipCode").css("background-color","yellow");
$("#ZipCode, #RanchName, #OwnerLastName").css({
"text-decoration": "none",
"color": "DodgerBlue",
"font-weight": "Bold",
"font-family": "Verdana",
"font-size": "12px",
"padding": "2px",
"vertical-align": "center",
"background-color":"White"
});
$(".menuTable").css({
"margin":"4px",
"display": "inline-block",
"padding":"2px",
"border-style":"solid",
"border-color":"DodgerBlue",
"border-width":"1px",
"border-collapse":"collapse",
"background-color":"White"
});
$(".menuHeading").css({
"text-decoration":"none",
"color": "DarkBlue",
"font-weight": "Bold",
"font-family": "Verdana",
"font-size": "10px",
"padding": "2px",
"padding-bottom": "5px",
"vertical-align": "center"
});
$(".menuOptions").css({"margin":"2px"});
$("#ZipCode").click(function(){
$("#ZipCode, #RanchName, #OwnerLastName").css("background-color",getDocumentBackgroundColor);
$("#ZipCode").css("background-color","yellow");
$("#RanchNameDataInput, #OwnerLastNameDataInput").hide();
$("#ZipCodeDataInput").show();
$('#ZipCodeSearchString').focus();
});
$("#RanchName").click(function(){
$("#ZipCode, #RanchName, #OwnerLastName").css("background-color",getDocumentBackgroundColor);
$("#RanchName").css("background-color","yellow");
$("#OwnerLastNameDataInput, #ZipCodeDataInput").hide();
$("#RanchNameDataInput").show();
$('#RanchNameSearchString').focus();
});
$("#OwnerLastName").click(function(){
$("#ZipCode, #RanchName, #OwnerLastName").css("background-color",getDocumentBackgroundColor);
$("#OwnerLastName").css("background-color","yellow");
$("#RanchNameDataInput, #ZipCodeDataInput").hide();
$("#OwnerLastNameDataInput").show();
$("#OwnerLastNameSearchString").focus();
});
});
$(function() {
$("#ZipCodeSearchString").autocomplete({
source: "NoMenu/RanchZipCodeSearchResults.cfm",
minLength: 2,
autoFocus: true,
delay: 200,
select: function(event, ui) {
$('#ZipCodeDataTable').html(
ui.item.value
);
}
});
});
$(function() {
$("#RanchNameSearchString").autocomplete({
source: "NoMenu/RanchNameSearchResults.cfm",
minLength: 2,
autoFocus: true,
delay: 200,
select: function(event, ui) {
$('#RanchNameDataTable').append(
'<div><a href="RanchPrintByRanchName.cfm?RanchName=' + ui.item.value + '" target="_blank">' + ui.item.value + '</a></div>'
);
document.getElementById('RanchNameSearchString').focus();
document.getElementById('RanchNameSearchString').select();
/*$('#RanchNameSearchString').focus(function () {
$('#RanchNameSearchString').select();
});*/
}
});
});
$(function() {
$("#OwnerLastNameSearchString").autocomplete({
source: "NoMenu/OwnerLastNameSearchResults.cfm",
minLength: 2,
autoFocus: true,
delay: 200,
select: function(event, ui) {
$('#OwnerLastNameDataTable').html(
ui.item.value
);
}
});
});
</script>
</head>
<body>
<div> </div>
<div class="menuTable">
<div class="menuHeading">
Select a Search Criteria
</div>
<div class="menuOptions">
<span id="ZipCode" title="Select to Search by Zip Code">
Zip
</span>
<span id="RanchName" title="Select to Search by Ranch Name">
Ranch
</span>
<span id="OwnerLastName" title="Select to Search by Owner Last Name">
Owner
</span>
</div>
</div>
<div></div>
<div class="menuTable">
<div id="ZipCodeDataInput">
<label for="OwnerLastNameSearchString" class="dataDisplay">
Zip Code:
</label>
<input
type="text"
id="ZipCodeSearchString"
name="ZipCodeSearchString"
size="25"
maxlength="25"
autofocus
title="Enter All or Part of a Zip Code"
autocomplete="off"
/>
<div class="dataDisplay">
Zip Codes
<div id="ZipCodeDataTable"></div>
</div>
</div>
<div id="RanchNameDataInput">
<label for="RanchNameSearchString" class="dataDisplay">
Ranch Name:
</label>
<input
type="text"
id="RanchNameSearchString"
name="RanchNameSearchString"
size="25"
maxlength="25"
title="Enter All or Part of a Ranch Name"
autocomplete="off"
/>
<div class="dataDisplay">
Ranch Names
<div id="RanchNameDataTable"></div>
</div>
</div>
<div id="OwnerLastNameDataInput">
<label for="RanchNameSearchString" class="dataDisplay">
Owner Last Name:
</label>
<input
type="text"
id="OwnerLastNameSearchString"
name="OwnerLastNameSearchString"
size="25"
maxlength="125"
title="Enter All or Part of an Owner Last Name"
autocomplete="off"
/>
<div class="dataDisplay">
Owner Last Names
<div id="OwnerLastNameDataTable"></div>
</div>
</div>
</div>
</body>
</html>
Lyndon
---People Remember about 10% of what you say ---They never forget how you made them feel. Covey