hi all,
i am having a login page which includes username, password,submit,clear. ater cuming to this page i am geting focus on textbox but wen i press clear button it is not focusing again on the username text box. so please help me.
Thank u.

Member Avatar for rajarajan2017

Sample:

<html>
<head>
<title>Add site</title>

</head>
<body onload="setFocus()">

<form action="add_site.php" method="post" name="add_site">
<input type=text name=add_url size=50 value="http://">
<input type=submit value=" add "> 
<input type="reset" value=" reset " name="Reset">
</form>

<script language="javascript">

function setFocus()
{
var field = document.add_site.add_url;
field.focus();
field.value = field.value;
field.focus();
}

</script>

</body>
</html>

Sample:

<html>
<head>
<title>Add site</title>

</head>
<body onload="setFocus()">

<form action="add_site.php" method="post" name="add_site">
<input type=text name=add_url size=50 value="http://">
<input type=submit value=" add "> 
<input type="reset" value=" reset " name="Reset">
</form>

<script language="javascript">

function setFocus()
{
var field = document.add_site.add_url;
field.focus();
field.value = field.value;
field.focus();
}

</script>

</body>
</html>

i had tried it. but i am not getting it wen i press clear button.

You may call that setFocus() function, when the reset button was pressed:

<input type="reset" value="reset" name="Reset" onclick="setFocus();">

P.S. I don't think a reset button is necessery on a login page.

Member Avatar for rajarajan2017

Yes that Right, bcoz when you click reset the page will not refresh, but my code call the setFocus on page load.

Just also call the fn onclick="setFocus();" from reset button input type.

It will work! It works!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.