Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Not Working 4

Status
Not open for further replies.

benkov

Programmer
Jun 16, 2004
13
GB
Hello,

I am a rookie javascripter (using pre-made scripts) and have edited a script slightly, but it is now returning an error.
Perhaps someone could check it over and tell me what is wrong

Thanks


<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<script language="javascript">
<!--//
/*This Script allows people to enter by using a form that asks for a
UserID and Password*/
function pasuser(form) {
if (form.pass.value=="0712") {
location="page2.html"
} else {
alert("Invalid Password")
}
}
}
//-->
</script>

<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1><i><b>Login
Area</b></i></h1></center></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center>
<script language="JavaScript">
<!--
var SymRealOnLoad;
var SymRealOnUnload;

function SymOnUnload()
{
window.open = SymWinOpen;
if(SymRealOnUnload != null)
SymRealOnUnload();
}

function SymOnLoad()
{
if(SymRealOnLoad != null)
SymRealOnLoad();
window.open = SymRealWinOpen;
SymRealOnUnload = window.onunload;
window.onunload = SymOnUnload;
}

SymRealOnLoad = window.onload;
window.onload = SymOnLoad;

//-->
</script>

 
Can you tell us where you are getting an error (after you do what?)

<.

 
Sorry,

I get the error message in the bottom left of IE and do not manage to login with the new modified script.

************ ORIGINAL SCRIPT (WORKING) ************

<script language="javascript">
<!--//
/*This Script allows people to enter by using a form that asks for a
UserID and Password*/
function pasuser(form) {
if (form.id.value=="sac") {
if (form.pass.value=="0712") {
location="page2.html"
} else {
alert("Invalid Password")
}
} else { alert("Invalid UserID")
}
}
//-->
</script>

<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1><i><b>Login
Area</b></i></h1></center></td></tr>
<tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input
name="id" type="text"></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center>

***************** NEW SCRIPT (NOT WORKING) **************

<script language="javascript">
<!--//
/*This Script allows people to enter by using a form that asks for a
UserID and Password*/
function pasuser(form) {
if (form.pass.value=="password") {
location="page2.html"
} else {
alert("Invalid Password")
}
}
//-->
</script>

<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1><i><b>Login
Area</b></i></h1></center></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center>
 
Try using Firefox. That browser has a built-in Javascript debugging console that is WONDERFUL for things like this. It will tell you the line and often the character on the line that's causing the problem.

Lee
 
I believe this is your problem:

Code:
<input name="[!]id[/!]" type="text">

You need to name this input tag something other than "id". Id is a "reserved word" for HTML.

<.

 
Actually id isn't a reserved word, but monksnake is absolutely correct that it's a poor idea to use HTML tag names and their attribute names for Javascript variable names.
 
Yeah, reserved word was in quotes, I don't think there are any reserved words in HTML, just words you shouldn't use.

<.

 
Damn I'm being stupid today, the reason your code isn't working is cause there is no starting form tag in your HTML.

You need to add this somewhere:

Code:
<form name="login">

I'd put it here:

Code:
[!]<form name="login">[/!]
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1><i><b>Login
Area</b></i></h1></center></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td>

<td><input name="pass" type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table>
[!]</form>[/!]
</center>

To be honest, I'd rewrite the entire thing, that's some sloppy stuff there. [afro]


<.

 
Whenever I see code like that, unformatted, unindented, just characters stacked one after the other, I don't bother trying to sort it out much. You'll find that most of the people who help out here much will give a LOT more attention to neatly formatted and indented code because it's easier to see what's there and figure out what it's supposed to do.

Lee
 
QUOTE:
Whenever I see code like that, unformatted, unindented, just characters stacked one after the other, I don't bother trying to sort it out much. You'll find that most of the people who help out here much will give a LOT more attention to neatly formatted and indented code because it's easier to see what's there and figure out what it's supposed to do.

Lee

END QUOTE

Ah... needs to be asthetically pleasing. As I said I don't do Javascript so really am not sure where to start and end and where to indent e.t.c. I just needed to adapt a script so that it only had a password field.

I also ran a debug in IE and it brought up a line and column. when I looked in DW, there was just a < from some formatting I think.

What my problem is is that the 'original script' works fine and the modified script brings an error. Just wondering really if anybody who does Javascript could see where there was an open command or a bracket int he wrong place e.t.c.

Thanks

Ben
 
See above, you were referring to (this.form) on pasuser and there was no form tag.

<.

 
I just needed to adapt a script so that it only had a password field.
Big red flag... there is no way to do security in Javascript.

Code:
function pasuser(form) {
if (form.pass.value=="password") {              
location="page2.html"
} else {
alert("Invalid Password")
}
}

Anyone can simply view the source and find out what password to enter.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Your new "NOT WORKING" script is missing the form tag, like monksnake said. The original script that works does contain the opening form tag.

Have you taken care of that problem?

Lee
 
By the way, I do know that there are 2 </form> tags in my example above, I'm assuming the non-red one would be deleted.

<.

 
Yeah. about the source thing. This security is purely superficial to stop really really stupid people. What I was thinking of though was framing the script so that the source would not show up immediately.

If I tell the problem, maybee somebody could suggest a better solution

I need a box whereby the viewer is required to enter 4 digits in order to get to a certain page.
I do not want to go down the line of usernames aswell due to problems in the past and too much complication
I originally had the renowned JS 'Gatekeeper' but people complained windows was stopping the popup so I need something else that is embedded in a page.

Anybody?

Thanks
 
QUOTE:

Your new "NOT WORKING" script is missing the form tag, like monksnake said. The original script that works does contain the opening form tag.

Have you taken care of that problem?

Lee

END QUOTE:

What can i say? That is exactly the kind of help I have come to expect on tek-tips and the reason I keep coming back. Those sorts of problems where they're childplay for a novice but trauma for a rookie

Thanks Lee & Thanks to everyone else who has contributed
 
benkov, since monksnake pointed out the missing <form> tag in your code above, perhaps you should give him a star as well?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
I hadn't originally noticed how much help the unsung monksnake had given.

My apologies for omiting you. I have now starred you.

Thanks

ben
 
Should be simple stuff, driving me crazy:

I just want to set the value of a hidden input on one form from another form.

the input I want to set the value of id = "pState"


No matter which type of referencing I try, I get

document.getElementById("pState") has no properties

Code:
function ChangeSelState(TheState)
{
var i = 0;
var sel = document.getElementById("StateList");
var stateHide = document.getElementById("pState");

alert(stateHide);

var myValue = TheState;
for(i==0; i < sel.options.length; i++)
{
if(sel.options[i].value == myValue)
{
sel.options[i].selected = true;
stateHide.value=myValue;
break;
}
}


I have tried using the document.forms['liensearch_frm'].elements['pState']
referencing, and get the same results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top