I have a question. I build example for you and now i will write what I want to do. I want to set cursor inside input file only when i click a link "simple". As you can see, function set_curso_in_files() have conditional exacution. I take condition from mysql database. When is true - execute function.
This is not working fine. You can test. For example script set the cursor inside the input filed but after reload page this disappear. I thougt that .ready help, but not. I tested also function : event.preventDefault() but i not working fine when i click on the other link and come back.
What should i write
function set_cursor_in_filed() {
$('#surname').focus();
}; // end set_cursor_in_filed
$(document).ready(function() {
$('#gen_fak').click(function(event) {
$.ajax({
type: "GET",
url: "do_exist.php",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function(json) {
var do_exist = 0;
for (var key in json) {
var row = json[key];
do_exist = row[0];
if (row[0] == 0) {
set_cursor_in_filed();
alert("Condition true");
} else {
alert("Condition false");
}
}
},
error: function(blad) {
alert("Error");
console.log(blad);
}
}); // end ajax
}); // end onclick
});
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
</head>
<body>
<p><a href="simple1.html"> simple1<a></p><br>
<p><a href="simple.html" id="gen_fak"> simple</a></p><br>
<input type="text" id="surname">
</body>
</html>