Reputation: 11
Below is a function that I have been trying to call to set focus on a text box, but it is not doing so. I would be thankful if anyone can tell me how to do this.
Thanks in advance :)
address1 is the id of the text box.
function address_validation(address1)
{
document.getElementById("address1").focus();
return false;
}
Upvotes: 1
Views: 4031
Reputation: 130
<html>
<head>
<style>
#txt:focus{
background:black;
}
</style>
</head>
<body>
<input type="text" id="txt"><BR>
<input type="button" onclick="btn()" value="set focus">
<script>
function btn(){
var txt = document.getElementById("txt");
txt.focus();
return false;
};
</script>
</body>
Upvotes: 0
Reputation: 6349
You are using "address1"
than address1
.
Your are supposing to get element by using dynamic id address1
but you have used static one "address1"
.
function address_validation(address1){
document.getElementById(address1).focus();
return false;
}
Upvotes: 3