Jump to content

[SOLVED] Javascript not being called from HTML


stockton

Recommended Posts

I have a web page that includes javascript as follows:-

<script language="JavaScript" type="text/javascript" src="js/AdjustmentFunctions.js"></script>

I have attempted and tested this when coded between the <head> and </head>

as well as after the </html> tags and cannot get it to work.

The html that should access this are :-

    <input type="button" value="Clear" Onclick="ClearAdjustmentForm()">

     

    <input type="button" value="Done" Onclick="AdjustmentDone()">

     

    <input type="button" value="Issue" Onclick="submit_click()">

     

    <input type="button" value="Print" Onclick="print()">

and those called functions are all within the AdjustmentFunctions.js file as follows:-

 

function AdjustmentDone()

{

window.location="Administration.php";

}

 

function ClearAdjustmentForm()

{

document.getElementById("CardNumber").value = "";

    document.getElementById("MemberName").innerHTML = "";

document.getElementById("Amount").value = "";

document.getElementById("Reason").value = "";

document.getElementById("CardNumber").focus();

}

 

function CheckAmount()

{

    if (!document.getElementById("Amount").innerHTML)

 

        {

 

        alert ("An value must entered");

 

        document.getElementById("Amount").focus();

 

        return false;

 

        }

else alert(document.getElementById("Amount").innerHTML);

}

 

function CheckReason()

{

if (!document.getElementById("Reason").value = "")

        {

 

        alert ("A reason is required and must be entered");

 

        document.getElementById("Reason").focus();

 

        return false;

 

        }

    if ((document.getElementById("Amount").innerHTML) &&

(document.getElementById("Reason").value))

{

document.getElementById("Issue").disabled=false;

}

}

 

function submit_click()

    {

    var bError = false;

    var strErrorMsg = "";

document.getElementById("Issue").disabled=false;

    Adjustments.submit();

    }

 

 

 

Other pages using javascript work fine. Just this one fails.

 

Please tell me how  I got this one wrong?

Link to comment
Share on other sites

Well your JavaScript looks clean and since I can't see your HTML file I will just suggest a couple of things:

 

Ensure that the code that links to the script is inside your <head> element.

<html>
<head>
	...
	<script language="JavaScript" type="text/javascript" src="js/AdjustmentFunctions.js"></script>
	...
</head>
...
</html>

 

The code that calls the script is using relative linking which means that the .js file needs to be in a folder called "js" that is in the current working directory. It that isn't the case you may need to change your pathing by starting from the webroot.

Link to comment
Share on other sites

The page looks like:-

<html>

 

<title>Adjustments</title>

 

<meta name="author" content="Alf C Stockton">

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

 

<!-- <META HTTP-EQUIV="Refresh" CONTENT="60;URL=Administration.php"> -->

 

<meta http-equiv="cache-control" content="no-cache">

 

<meta http-equiv="expires" content="Mon, 22 Jul 2000 11:12:01 GMT">

 

<link rel="stylesheet" type="text/css" href="./style/style.css">

<script language="JavaScript" type="text/javascript" src="js/ajax.js"></script>

 

<script language="JavaScript" type="text/javascript" src="js/AdjustmentFunctions.js"></script>

</head>

 

 

 

<?php

 

require_once('includes/configuration.php');    // database connect script & the rest.

 

require_once('includes/logo.inc');

 

// We 1st check if user has logged on and has authority to add, delete or amend Earn Rates.

 

 

 

  if ((!$_SESSION['UID']) && (!$_SESSION['Usrname'])) // Not logged in

 

      {

 

      $Message = sprintf("%s %d <br> Logon to be able to access this task!", __FILE__, __LINE__);

 

      trigger_error($Message, E_USER_ERROR);

 

      exit;

 

      }

 

    if ($_SESSION['UserRights'] < 8)

 

        {

 

        $Message = sprintf("%s %d <br>User %s with access level %d does not have authority for this task!",

 

                          __FILE__, __LINE__,  $_SESSION['Usrname'], $_SESSION['UserRights']);

 

        trigger_error($Message, E_USER_ERROR);

 

        exit;

 

        }

 

?>

 

<h2>Adjustments</h2>

 

<center>

 

  <form name=Adjustments ID=Adjustments method=post action="InsertAdjustment.php?UID=<?php echo $intUserID ?>">

 

  <table border=3 frame=box cellpadding=10 width=40% align=center>

 

  <tr>

 

  <td>Event:<br></td>

 

<?php

 

    DBConnect();        // Connect to Events database

 

// Get todays date.

 

    $Datum = date("Y-m-d H:i:s");    /* 2006-03-17 23:22:32 */

 

    $SQL = "SELECT EventID, EventName, LastDrawDate FROM Event WHERE '$Datum'>=EndDate AND '$Datum'<=LastDrawDate";

 

    $rs = mssql_query($SQL, $link);

 

    echo "<br /><center><td><select name='Event'>";

 

    $Count = 0;    while ($row = mssql_fetch_array($rs))

 

        {

 

        $EventID = $row['EventID'];

 

        $Message = sprintf("%s", $row['EventName']);

 

        $LastDrawDate = $row['LastDrawDate'];

 

        echo "<option value=$EventID>$Message</option>";

 

        ++$Count;

 

        }

 

    if ($Count == 0)

 

        {

 

        $Message = sprintf("%s %d <br>No events currently applicable!", __FILE__, __LINE__);

 

        trigger_error($Message, E_USER_ERROR);

 

        exit;

 

        }

 

    $SQL = "Select EarnTypeID, TableType, EarnType from EarnType";

 

    $rs = mssql_query($SQL, $link);

 

    echo '<tr><td>Earn Type :<br /></td>';

 

    echo '<td><select name="Earn Type">';

 

    $Count = 0;    while ($row = mssql_fetch_array($rs))

 

        {

 

        $EarnTypeID = $row['EarnTypeID'];

 

        $EarnType = sprintf("%s", $row['TableType']);

 

        echo '<option value='.$EarnTypeID.'>'.$EarnType.'</option>';

 

        ++$Count;

 

        }

 

    if ($Count == 0)

 

        {

 

        $Message = sprintf("%s %d <br>No Earn Types defined!", __FILE__, __LINE__);

 

        trigger_error($Message, E_USER_ERROR);

 

        exit;

 

        }

 

    DBDisConnect();

 

?>

 

 

 

    </td></tr>

 

    <tr><td>

 

    <font size=+1>Member No:<br />

 

    Member Name :<br />

 

    Amount :<br />

 

    Reason :<br /></font>

 

    </td><td>

 

    <input type=text name="CardNumber" id="CardNumber" onBlur="sendRequest('<?php echo $GetName.",".$EventID ?>',this.value)">

 

    <div style="position:relative;" id="MemberName";><b>Member name.</b></div>

 

    <div style="position:relative;"><input type=text name="Amount" id="Amount" onBlur="CheckAmount()"></div>

 

    <div style="position:relative;"><input type=text name="Reason" id="Reason" onBlur="CheckReason()"></div>

 

    </td></tr>

 

 

 

    </table>

 

    </form>

 

    <br />

 

    <input type="button" value="Clear" Onclick="ClearAdjustmentForm()">

 

     

 

    <input type="button" value="Done" Onclick="AdjustmentDone()">

 

     

 

    <input type="button" value="Issue" Onclick="submit_click()">

 

     

 

    <input type="button" value="Print" Onclick="print()">

 

    <div id="loadingNode";></div>

 

 

 

    </center>

 

<?php

 

require_once('includes/tail.inc');

 

?>

 

</body>

 

</html>

 

<script language="JavaScript" type="text/javascript">

 

document.getElementById("Issue").disabled=true;

 

document.getElementById("CardNumber").focus();

 

</script>

 

and the AdjustmentFunctions.js is in the correct folder and the Ajax scripts work fine.

Link to comment
Share on other sites

Generally when your JS stops working it can also be because there is a JS error somewhere. If you use firefox (and have the Web Developer add-on installed) you can see the Browser's Error Console and if your page in firefox it will show you where your JS is breaking, if that is the case.

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.