...

View Full Version : Simple: Using text from form inputs as variables



toymachine22122
01-05-2004, 11:36 PM
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 (http://www.pagetutor.com/keeper/index.html).

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

COBOLdinosaur
01-06-2004, 12:01 AM
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;

Willy Duitt
01-06-2004, 12:56 AM
In addition to add to COBOLdinasaur's post;

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

Try this:

<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

toymachine22122
01-06-2004, 04:36 PM
Thanks!!

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

Willy Duitt
01-06-2004, 08:58 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum