Forum Moderators: open

Message Too Old, No Replies

form submit in Mozilla

         

mcibor

5:41 pm on Nov 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello! I'm still a newbie and have a small problem: I'm trying to make a javascript error find in changing users pass. Below is an exempary code. Two inputs and a button (<input type="button"> couldn't change font size). In javascript I'm checking if there's written data and if it's the same.
The problem is that the form is always submitted in Mozilla. In IE it's working all right.
I found out that with <input type="button"> it's working fine, however Mozilla doesn't change the font. My question therefore is: How to disable submitting form while clicking on a <button> element.

Best regards
Michal Cibor

The code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function java_change()
{
var a = document.a;
if(a.b.value == "")
{
alert("Please fill in the input b");
a.b.select();
}
else
{
if(a.b.value!= a.c.value)
{
alert("Input b and c must be the same.")
a.c.select();
}
else
{
if(confirm("Are you sure?"))
{
a.submit();
}
}
}
}
//-->
</script>
</head>
<body>
<form name="a" action="l.html" method="post">
<input type="text" name="b"><input type="text" name="c">
<button onclick="java_change()">Change</button></form>
</body>
</html>

BjarneDM

10:54 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



you are using the IE DOM model in your javascript instead of the w3c DOM model, so of course your scrip'll only work in IE and no other browser.

The fixes are here:
1) give your elements an id alongside their name. The id and name can be the same.
2) use the w3c document.getElementById() to reference the elements instead of the flat IE DOM model.

mcibor

9:15 pm on Nov 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. It wasn't a problem. However I'll correct it. The main and real problem was the button element.

It (the <button> was submitting the form, where I want javascript to do it.

Question is: "Is there a possibility to stop the <button> element from submitting a form?".

Thnx.

BjarneDM

8:48 pm on Nov 8, 2004 (gmt 0)

10+ Year Member



<button onclick="java_change();return false;">Change</button>
should do it

mcibor

9:50 pm on Nov 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you, thank you, thank you! It's working now!
Thanks BjarneDM!