Jump to content

Field Focus Doed Not Persist


s4surbhi2218

Recommended Posts

Hey,

My problem is that focus to filed happens and un focuses soon after that , however i want it to persist till user resubmits , i am using the following

 

<html>

<head>

<script language="javascript">

function fnc_Validate()

{

var str= '';

if(document.getElementById('name1'))

{

if(document.getElementById('name1').value == '')

{

alert('Cannot be left Blank');

document.getElementById('name1').focus();

return false;

}

}

str = "Short1.php";

document.frmname.action = str;

document.frmname.submit();

}

</script>

</head>

<body>

<form name='frmname' method='post'>

<input type="text" name="name1" id="name1">

<input type="text" name="name2" id="name2">

<input type="text" name="name3" id="name3">

<input type="submit" value="shorten" onclick="fnc_Validate();">

</form>

</body>

</html>

 

Any help would be great , thanks

Link to comment
https://forums.phpfreaks.com/topic/271855-field-focus-doed-not-persist/
Share on other sites

Please use code tags when you show any code. It makes it much easier to look through.

 

Without changing a whole lot of your code ..

Demo: http://xaotique.no-ip.org/tmp/28/

 

<html>
   <head>
       <script language="javascript">
           window.addEventListener("load", function()
           {
               window.document.frmname.addEventListener("submit", function(e)
               {
                   e.preventDefault();

                   var str= '';

                   if (document.getElementById('name1'))
                   {
                       if (document.getElementById('name1').value == '')
                       {
                           alert('Cannot be left Blank');
                           document.getElementById('name1').focus();

                           return false;
                       }
                   }

                   str = "Short1.php";
                   document.frmname.action = str;
                   document.frmname.submit();
               }, false);
           }, false);
       </script>
   </head>
   <body>
       <form name='frmname' method='post'>
           <input type="text" name="name1" id="name1">
           <input type="text" name="name2" id="name2">
           <input type="text" name="name3" id="name3">
           <input type="submit" value="shorten">
       </form>
   </body>
</html>

Please use code tags when you show any code. It makes it much easier to look through.

 

Without changing a whole lot of your code ..

Demo: http://xaotique.no-ip.org/tmp/28/

 

<html>
<head>
<script language="javascript">
window.addEventListener("load", function()
{
window.document.frmname.addEventListener("submit", function(e)
{
e.preventDefault();

var str= '';

if (document.getElementById('name1'))
{
if (document.getElementById('name1').value == '')
{
alert('Cannot be left Blank');
document.getElementById('name1').focus();

return false;
}
}

str = "Short1.php";
document.frmname.action = str;
document.frmname.submit();
}, false);
}, false);
</script>
</head>
<body>
<form name='frmname' method='post'>
<input type="text" name="name1" id="name1">
<input type="text" name="name2" id="name2">
<input type="text" name="name3" id="name3">
<input type="submit" value="shorten">
</form>
</body>
</html>

 

this solved my prob , yes i get your point of using code tags. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.