Browser 'form' differences?

E

evan.tually

I'm new to trying to use javascript, so I'm probably doing something
wrong.
This code works with MSIE, but not with Firefox. And advice greatly
appreciated.

In HTML page "head" section, I have this line:
<script language="javascript" type="text/javascript"
src="lib/form.js"></script>

In the "body", this is the FORM:
<form>
<input type="button" value="Log in to Upload" onClick="login()"> <br>
<input type="button" value="Forgot Password" onClick="sendpw()">
<input type=text name="pwd" size="48"> Enter registered email address
and click "Forgot Password"
</form>

The file "form.js" contains:
function login() {
vMsg="lib/login.php";
window.location=vMsg;
}
function sendpw() {
pw=document.getElementById('pwd').value;
if (pw == '') {
alert("Enter a valid email address");
}
else {
vMsg="lib/check.php?USERPW="+pw;
window.location=vMsg;
}
}

Thanks in advance,
Evan
 
A

ASM

(e-mail address removed) a écrit :
I'm new to trying to use javascript, so I'm probably doing something
wrong.
This code works with MSIE, but not with Firefox. [...]
<input type="button" value="Forgot Password" onClick="sendpw()">
<input type=text name="pwd" size="48"> Enter registered email address
and click "Forgot Password"

<input id="pwd" name="pwd" type=text size="48">

with an ID, because
function sendpw() {

here you want to get an object (or element) by its ID
get element by ID
pw=document.getElementById('pwd').value;

With IE it works with name because IE uses to aproximate whatever he touchs
 
R

Richard Cornford

I'm new to trying to use javascript, so I'm probably doing
something wrong.
This code works with MSIE, but not with Firefox. And
advice greatly appreciated.

The _only_ part of this that should be implemented with javascript is
the validation of the non-empty password (which should be done with an -
onsubmit - handler on the form element). The rest should be done with a
normal HTML form (real submit buttons) and PHP (in your case) on the
server. Part of learning javascript is learning when not to use it.

<input type=text name="pwd" size="48"> Enter ...
function sendpw() {
pw=document.getElementById('pwd').value;
<snip> ^^^^^^^^^^^^^^

Your HTML contains no elements with the ID attribute "pwd". IE is in
error in returning elements with the NAME attribute, but no other
browsers repeat that fault. See:-

<URL: http://jibbering.com/faq/faq_notes/form_access.html >

Richard.
 
E

evan.tually

Thanks! for your responses, and for your advice. I appreciate your
time.
Regards,
Evan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top