Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple: Using text from form inputs as variables

    I am trying to write a simple script that will allow people with a password to edit the web site from an in-site engine. Almost all of this has been already completed with CGI, but I need this one JavaScript for an HTML page. I am by no means experienced at javascript, and this is really my first javascript that is not just a modified version of someone else's script. Anyway, what I'm trying to make is a JavaScript command line, which will appear as a text box on an HTML page.
    If someone types "Cascade" into the box and hits Enter, it should take them to the cascadeoptions.html page
    If someone types "CACLS" into the box it should take them to caclmod.cgi
    If neither of these are typed into the command line, it should take them to whatever page they type, with the extension of ".html"
    In other words, if they type "redrose" in the command line it should take them to "redrose.html"
    A good example of this is the GateKeeper script found on PageTutor.com by Joe Barta. You can take a look at that Here.

    Here is a page containing solely the HTML tags and the script as i have it now. could someone please tell me what's wrong with it?
    <HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--
    /****************************************
    * Command Line Script, by Will Dresh (w.dresh@verizon.net)
    * You are free to use this on your web site as long as this notice stays intact
    ****************************************/
    function CMD() {
    var CMDText = CMDLine();
    if ( CMDText == "Cascade" ) { href = cascadeoptions.html; }
    elseif ( CMDText == "CACLS" ) { href = cacls.cgi; }
    else { this.location.href = CMDText + ".html" }
    //--></SCRIPT></HEAD><BODY BGCOLOR="black" TEXT="limegreen"><FORM><INPUT TYPE="text" NAME="CMDLine"><INPUT TYPE="submit" VALUE="Enter" onClick="CMD() return false;"></FORM></BODY></HTML>
    Thanks

  • #2
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    411
    Thanks
    2
    Thanked 32 Times in 32 Posts
    var CMDText = CMDLine();

    CMDLine is not a method or function, just a name property

    I think what you want is:

    var CMDText = document.forms[0].CMDLine.value;
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In addition to add to COBOLdinasaur's post;

    You are missing a closing bracket }
    and your href should be location.href

    Try this:
    Code:
    <HTML>
    <HEAD>
    <script type="text/javascript">
    <!--//
    function CMD() {
      var CMDText = document.forms[0].CMDLine.value;
          if ( CMDText == 'Cascade') {
               location.href = 'cascadeoptions.html';
             }
          else if ( CMDText == 'CACLS' ) {
               location.href = 'cacls.cgi';
             }
          else {
               location.href = CMDText + '.html';
             }
          }
    //-->
    </script>
    </HEAD>
    
    <BODY BGCOLOR="black" TEXT="limegreen">
    <FORM>
    <INPUT TYPE="text" NAME="CMDLine"><BR>
    <INPUT TYPE="button" VALUE="Enter" onClick="CMD()">
    </FORM>
    </BODY>
    </HTML>
    .....Willy

  • #4
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!!

    Just one more question, how do I get it to launch in a new window?

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Since this is a puesdo password login I would use location.replace which should remove the login page from the recent history and prevent a user from returning thru their back button.

    EG: Change all instances of location.href with location.replace

    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •