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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javscript Problems in FireFox 1

Status
Not open for further replies.

tyksweb

Programmer
May 8, 2008
5
US
Hey Everyone,

I'm new to Tek-Tips, so please bear with me.

I'm trying to create a website for my work while teaching myself how to do this. I have gotten almost everything done, but I'm having troubles with my JavaScript. I am using a JavaScript function as a way to validate a password received from a form. I've been told this isn't the best way to do it, because it can be viewed by everyone, but we are just tryin to divert people who don't need to go to that part of the site as opposed to keeping it completely secure. There isn't any "important" information, its just internal use.

Anyways, I tried setting the javascript to a .js file, and it only works in IE. Then I tried setting it up within the <head> section of the document, and it still only works in IE. A lot of the people that would use it use primarily FireFox.

Does anyone know how to fix this? Any help would be great.

Thanks
 
Show us how you are setting up your code. It'll be a typo or something.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
The function calls from the value typed into the text box that is named "pass1". The input type for the text box is "password". It decides if it is correct and takes you to the next page, or will say that it is incorrect.

function passPro()
{
if ("password"!=pass1.value)
{
// if value is NOT correct,
// Alert it is not correct and return false
alert("Password Incorrect.");
return false;
}
else
{
// if value is correct,
// Return true, and open next page...
document.location.href="url to next page";
return true;

}
}

As I stated before, it is pretty simple and not the most secure, but is used more as a way to defer people that don't belong there. It is also probably pretty sloppy since I'm teaching myself everything having to do with HTML and JavaScript. I've been slowly working on it for a a while between other things at work and decided it was time to ask for help.

Thanks again.
 
You will have to be a little more specific for non-IE browsers when attempting to access form fields (etc).

Assuming markup like this:
Code:
...
<form action="" method="post">
<input name="pass1" id="pass1" value="">
<input name="pass2" id="pass2" value="">
...
</form>
...
Then you can access the form field values like this (across all browsers):
Code:
...
var pass1Val = document.getElementById('pass1').value;
var pass2Val = document.getElementById('pass2').value;
...

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
... and just for extra credit, you may find that you get tired of typing all that cruft pretty soon. Here is a little routine that goes into nearly all my pages, just so I don't have to type "document.getElementById() and get all the camel-case stuff right:

function idGet(str) {
return document.getElementById(str);
}

It takes an id string as a parameter, and returns a pointer to the object so identified.
 
The javascript framework Prototype (for example), has done something similar - and uses a dollar symbol to represent document.getElementById().

Of course, the $ adds a bunch of extra stuff to the object, but that's for another conversation [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top