最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - html script src="" triggering redirection with button - Stack Overflow

programmeradmin2浏览0评论

i have the following login.html page for login located in design folder.

<html>
<head>
<title>Login Page</title>
<script src="../Script/login.js">

</script>

</head>
<body>
<h3> Login</h3>
<form name="login">
Location code  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp; <select name="ddl1"><br>
  <option value="loc1" size=20>LH</option>
  <option value="loc2">AT</option>
  <option value="sel" selected>-------select------</option>
</select>
<br><br>
Enter UserName &nbsp;&nbsp;:  &nbsp;&nbsp;<input type="Text" name="inp1" size=20><br><br>
Enter Password &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;  <input type="password" name="pwd1" size=20><br><br>

<button type="button" name="login" onclick="log()">Login</button> 

</form>

</body>
</html>

and also i have onother folder named scripts that contains the following login.js file

function log()
{
 var li=parent.head.document.getElementById('lin');
 var lo=parent.head.document.getElementById('lou');
 
 var passid = document.login.pwd1.value;
 var passid_len = passid.length;
 
 var un=document.login.inp1.value;

 var e = document.getElementById("ddl1");
var strUser = e.options[e.selectedIndex].value;

if(strUser=="loc1" || strUser=="loc2")
{
  if (passid_len >= 5) 
  {  

   if(un=="admin")
    { 
     parent.nav1.location.href = 'nav_admin.html';
     document.write("Hello admin");
     li.style.display = "none";
     lo.style.display = "";
    }
    else if(un=="clerec")
    {
      parent.nav1.location.href = 'nav_clerk_reception.html';
      document.write("Hello reception clerk");
      li.style.display = "none";
      lo.style.display = "";
    }
    else if(un=="cledep")
    {
     parent.nav1.location.href = 'nav_clerk_departemnt_operations.html';
     document.write("Hello dept clerk");
     li.style.display = "none";
     lo.style.display = "";
    }
    
     else if(un=="guest")
    {
     parent.nav1.location.href = 'nav_guest.html';
     document.write("Hello Guest");
     li.style.display = "none";
     lo.style.display = "";
     }
     else
    {
     document.write("Wrong user name and password");
    } 
   }
   else
    {
     document.write("password should be minimum 5 characters");
    }
   }
   else
    {
        document.write("Choose Location");
    }
 }
 
 function fnlog1()
{
 var lo=parent.head.document.getElementById('lou');
 var li=parent.head.document.getElementById('lin');
 lo.style.display = "none";
 li.style.display = "";
 parent.nav1.location.href = 'navigate.html';
 }

when i click log in button nothing works....no redirection takes place....html page does not call log() function....

i have the following login.html page for login located in design folder.

<html>
<head>
<title>Login Page</title>
<script src="../Script/login.js">

</script>

</head>
<body>
<h3> Login</h3>
<form name="login">
Location code  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp; <select name="ddl1"><br>
  <option value="loc1" size=20>LH</option>
  <option value="loc2">AT</option>
  <option value="sel" selected>-------select------</option>
</select>
<br><br>
Enter UserName &nbsp;&nbsp;:  &nbsp;&nbsp;<input type="Text" name="inp1" size=20><br><br>
Enter Password &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;  <input type="password" name="pwd1" size=20><br><br>

<button type="button" name="login" onclick="log()">Login</button> 

</form>

</body>
</html>

and also i have onother folder named scripts that contains the following login.js file

function log()
{
 var li=parent.head.document.getElementById('lin');
 var lo=parent.head.document.getElementById('lou');
 
 var passid = document.login.pwd1.value;
 var passid_len = passid.length;
 
 var un=document.login.inp1.value;

 var e = document.getElementById("ddl1");
var strUser = e.options[e.selectedIndex].value;

if(strUser=="loc1" || strUser=="loc2")
{
  if (passid_len >= 5) 
  {  

   if(un=="admin")
    { 
     parent.nav1.location.href = 'nav_admin.html';
     document.write("Hello admin");
     li.style.display = "none";
     lo.style.display = "";
    }
    else if(un=="clerec")
    {
      parent.nav1.location.href = 'nav_clerk_reception.html';
      document.write("Hello reception clerk");
      li.style.display = "none";
      lo.style.display = "";
    }
    else if(un=="cledep")
    {
     parent.nav1.location.href = 'nav_clerk_departemnt_operations.html';
     document.write("Hello dept clerk");
     li.style.display = "none";
     lo.style.display = "";
    }
    
     else if(un=="guest")
    {
     parent.nav1.location.href = 'nav_guest.html';
     document.write("Hello Guest");
     li.style.display = "none";
     lo.style.display = "";
     }
     else
    {
     document.write("Wrong user name and password");
    } 
   }
   else
    {
     document.write("password should be minimum 5 characters");
    }
   }
   else
    {
        document.write("Choose Location");
    }
 }
 
 function fnlog1()
{
 var lo=parent.head.document.getElementById('lou');
 var li=parent.head.document.getElementById('lin');
 lo.style.display = "none";
 li.style.display = "";
 parent.nav1.location.href = 'navigate.html';
 }

when i click log in button nothing works....no redirection takes place....html page does not call log() function....

Share Improve this question edited Aug 30, 2020 at 21:45 HoldOffHunger 20.9k11 gold badges119 silver badges146 bronze badges asked Oct 15, 2013 at 5:53 Karthik_SDKarthik_SD 6331 gold badge6 silver badges22 bronze badges 1
  • is there any error on browser ... please do use developer tool and try to find out the error ... also check if you have given correct path of the js file – Bhushan Kawadkar Commented Oct 15, 2013 at 5:56
Add a comment  | 

4 Answers 4

Reset to default 10

First you are linking the file that is here:

<script src="../Script/login.js"> 

Which would lead the website to a file in the Folder Script, but then in the second paragraph you are saying that the folder name is

and also i have onother folder named scripts that contains the the following login.js file

So, this won't work! Because you are not accessing the correct file. To do that please write the code as

<script src="/script/login.js"></script>

Try removing the .. from the beginning of the code too.

This way, you'll reach the js file where the function would run!

Just to make sure:

Just to make sure that the files are attached the HTML DOM, then please open Developer Tools (F12) and in the network workspace note each request that the browser makes to the server. This way you will learn which files were loaded and which weren't, and also why they were not!

Good luck.

Your foldername is scripts ?

Change

<script src="../Script/login.js">

to

<script src='scripts/login.js' type='text/javascript'></script>

I was having this problem but i found out that it was a permissions problem I changed my permissions to 0744 and now it works. I don't know if this was your problem but it worked for me.

your folder name is scripts..

and you are Referencing it like ../script/login.js

Also make sure that script folder is in your project directory

Thanks

发布评论

评论列表(0)

  1. 暂无评论