#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2005
    Posts
    1
    Rep Power
    0

    How to execute (run) .JS file from HTML file?


    HI,

    I have one folder i.e. Practice.
    It contains three files.

    1) Main.html
    2) Write.js
    3) Delete.js

    code is here:

    1) Main.html

    <HTML>
    <HEAD>
    <TITLE> Showing how to modify Register (Regedit.exe) </title>
    <SCRIPT LANGUAGE="JavaScript" SRC="Write.js">
    </SCRIPT>
    <SCRIPT LANGUAGE="JavaScript" SRC="Delete.js">
    </SCRIPT>
    </HEAD>

    <BODY BGCOLOR="black">
    <INPUT TYPE="button" VALUE="Write into Register" onclick="Write">
    <INPUT TYPE="button" VALUE="Delete from Register" onclick="Delete">
    </BODY>
    </HTML>


    2) Write.js

    var WSHShell = WScript.CreateObject("WScript.Shell");

    WSHShell.RegWrite("HKCU\\Software\\Microsoft\\Wind ows\\CurrentVersion\\Policies\\System\\DisableRegi stryTools",1,"REG_DWORD");


    3) Delete.js

    var WSHShell = WScript.CreateObject("WScript.Shell");

    WSHShell.RegDelete("HKCU\\Software\\Microsoft\\Win dows\\CurrentVersion\\Policies\\System\\DisableReg istryTools");


    There are two buttons in Main.html. i.e.
    1) Write into Register
    2) Delete from Register

    What I want is

    If i click on Write into Register button, then i want execute Write.js

    If i click on Delete from Register button, then i want execute Delete.js

    How to executes Write.js & Delete.js files from Main.html?
    I am using IE6.

    Please correct code for above files.

    Please can anyone help me with this?


    Rambabu
    Friday, August 5, 2005
    I am using IE6
  2. #2
  3. Expert Learner
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Feb 2005
    Location
    Wisconsin
    Posts
    1,909
    Rep Power
    97
    Alright, I've tried to clean this up for you. I've made many changes, but I'm just going to go over the main ones. If you have any questions, don't be afraid to ask.

    1. No longer use the language="JavaScript" as it is deprecated. Use type="text/javascript"
    2. There is no need to have your javascript code in seperate files, so I combined it into one.
    3. Don't forget to wrap form inputs with <form> tags.

    index.html
    Code:
    <html>
    	<head>
    		<title>Showing how to modify Register (Regedit.exe)</title>
    		<script type="text/javascript" src="files.js"></script>
    	</head>
    
    <body>
    	<button type="submit" onclick="formWrite()">Write into Register</button>
    	<button type="submit" onclick="formDelete()">Delete from Register</button>
    </body>
    
    </html>
    files.js
    Code:
    function formWrite(){
    
    	var WSHShell = WScript.CreateObject("WScript.Shell");
    
    	WSHShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion \\Policies\\System\\DisableRegistryTools",1,"REG_DWORD");
    
    }
    
    function formDelete(){
    
    	var WSHShell = WScript.CreateObject("WScript.Shell");
    
    	WSHShell.RegDelete("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion \\Policies\\System\\DisableRegistryTools");
    
    }
    Note: These forums automatically put spaces in really long words, so don't forget to fix them accordingly.
    Last edited by baseballdude_; August 9th, 2005 at 04:11 PM.
  4. #3
  5. Web-Standards Evangelist
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Nov 2003
    Posts
    1,522
    Rep Power
    14
    You don't need the blank <form> element unless there's some actual submission. The HTML <input />, <button>, and <textarea> elements don't need to be in a form unless they're providing input for a page to send the data to.

    Finally, you do realise that your code won't run on browsers other than IE nor for IE if your site isn't in the "Trusted Sites" zone?
  6. #4
  7. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2922
    this is probably for Intranet stations otherwise the code is indeed pointless.
    anyway, BBD gave the correct code - you need to wrap the code inside separate functions and call them upon clicking the buttons... form tags are not needed.

Similar Threads

  1. ASP / HTML File Differences ?!
    By mestonian in forum ASP Development
    Replies: 3
    Last Post: May 6th, 2005, 04:05 AM
  2. create table in html file within vb6
    By kmalika in forum Visual Basic Programming
    Replies: 9
    Last Post: December 27th, 2004, 06:46 AM
  3. Save as prompt for an html file
    By JoeM in forum ASP Development
    Replies: 0
    Last Post: May 19th, 2004, 12:39 AM
  4. Web serverístatistical analysis
    By cso in forum ASP Development
    Replies: 0
    Last Post: April 19th, 2003, 12:35 PM
  5. How to Save Edited HTML File to External Website
    By xxist in forum ASP Development
    Replies: 1
    Last Post: March 19th, 2003, 01:59 AM

IMN logo majestic logo threadwatch logo seochat tools logo