[javascript] html script src="" triggering redirection with button

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

This question is related to javascript html src

The answer is


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.


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


Your foldername is scripts ?

Change

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

to

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

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to src

OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this? Angular 4 img src is not found Rotate an image in image source in html html script src="" triggering redirection with button What is the right way to write my script 'src' url for a local development environment? How to properly reference local resources in HTML? Dynamically add script tag with src that may include document.write Programmatically change the src of an img tag Get img src with PHP Javascript : get <img> src and set as variable?