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
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>

Link to comment
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>

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.