-
August 13th, 2007, 12:32 PM
#1
Very strange problem in firefox
I have a subscription page which is validated using a javascript
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no">
<meta name="MSSmartTagsPreventParsing" content="true">
<title>TITLE</title>
<link href="css/css_ibs.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/scripts.js"></script>
</head>
<body>
<form action="" method="post" name="cad" onSubmit="return validacad(this);" style="display:inline;">
<input name="name" type="text" class="textBoxcad" >
<input name="company" type="text" class="textBoxcad" />
<input name="image" type="image" src="images/btn_ok.gif" />
</form>
</body>
</html>
When I access this page for the 1st time and hit the subscribe button it doesn´t run the javascript and adds me without having filled any field.
But after having registred if I hit the button again it runs the javascript and asks me to inform values for the fields.
It´s even more strange cause I have a login form on the right of the page and it always work. If I try to login without informing anything the javascript asks me to fill the fields. It always works.
This only happens in firefox
Any ideas of why this only works in the 2nd time?
Last edited by PeejAvery; August 13th, 2007 at 12:49 PM.
-
August 13th, 2007, 12:49 PM
#2
Re: Very strange problem in firefox
Please remember to use code tags when posting.
Also, you reference a JS file. Without that file, there is no way we can help debug. Have you checked the Error Console in Firefox for errors?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 5th, 2007, 07:37 AM
#3
Re: Very strange problem in firefox
You don't have any object in your HTML code to trigger a Javascript function or in this case submit the form. You should remove the submission part on the form tag and complete using something like:
HTML Code:
<input name="image" type="image" src="images/btn_ok.gif" onclick="Javascript: yourfunction(yourparams);"/>
Anyway this isn't a FF related issue.
-
September 5th, 2007, 08:16 AM
#4
Re: Very strange problem in firefox
Originally Posted by davidc2p
You don't have any object in your HTML code to trigger a Javascript function or in this case submit the form.
Yes, he does. He uses onsubmit in the <form> tag.
Originally Posted by davidc2p
You should remove the submission part on the form tag and complete using something like:
HTML Code:
<input name="image" type="image" src="images/btn_ok.gif" onclick="Javascript: yourfunction(yourparams);"/>
I disagree with this for three reasons.
1. Note that you have "javascript:" in your onclick event. Since onclick is already a JavaScript event, you have no reason to put "javascript:" there.
2. If the user has an input tag and presses the return key, your code will not fire.
3. Using onsubmit in the <form> is the most efficient way because it traps events of the form itself.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 5th, 2007, 08:21 AM
#5
Re: Very strange problem in firefox
1. Note that you have "javascript :" in your onclick event. Since onclick is already a JavaScript event, you have no reason to put "javascript :" there.
2. If the user has an input tag and presses the return key, your code will not fire.
3. Using onsubmit in the <form> is the most efficient way because it traps events of the form itself.
I disagree with these 3 reasons for 3 reasons:
1- Always a good practice to quote what kind of script you are calling even if implicit.
2 - the initial program is using an INPUT type image.
3 - onsubmit is a very limited event, always try to manage your submission yourself, you will deal with a much larger range of possibilities.
-
September 5th, 2007, 09:04 AM
#6
Re: Very strange problem in firefox
A few quick point-outs:
- Your document is not valid XHTML. All tags must be closed, and tag names/attributes must be lower case:
Code:
<meta http-equiv="imagetoolbar" content="no">
<meta name="MSSmartTagsPreventParsing" content="true">
should be:
Code:
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
...and...
Code:
<form action="" method="post" name="cad" onSubmit="return validacad(this);" style="display:inline;">
<input name="name" type="text" class="textBoxcad" >
should be:
Code:
<form action="" method="post" name="cad" onsubmit="return validacad(this);" style="display:inline;">
<input name="name" type="text" class="textBoxcad" />
Other than those, there are no errors with the little code you posted. You will have to show more code like PeejAvery said.
davidc2p:
I very much disagree on point 3. If the purpose of the script was to occur when the user clicks a button (be it the submission button or not), then it should be onclick. This is not the case here. The purpose of the script is to run when the form is submitted. The correct attribute to use is onsubmit. There are several ways a form can be submitted, some of which do not include clicking the submission button. Theoretically, a client such as a mobile phone could have a shortcut which submits the currently active form when a certain key is clicked.
As to point #1, it's redundant. The web client sends everything in the attribute to its default script handler. It does not check if it begins with "javascript:" and sends it to JavaScript, it sends everything to JavaScript which then removes the "javascript:" part. To change the default script handler you would use the HTTP header (or meta tag) Content-Script-Type. I have never, ever, seen a practical implementation of this, however.
-
September 5th, 2007, 09:17 AM
#7
Re: Very strange problem in firefox
If the purpose of the script was to occur when the user clicks a button (be it the submission button or not), then it should be onclick. This is not the case here. The purpose of the script is to run when the form is submitted. The correct attribute to use is onsubmit.
In that case, i would totally aggree with you, but where would be the trigger for the submission? what is the button image for if not to trigger the script submission?
-
September 5th, 2007, 09:39 AM
#8
Re: Very strange problem in firefox
The submit button is one way to submit the form. Not the only way. The code in this case is for validating the form so that it doesn't have to be submitted with invalid values, and putting validation on only one of the methods for submitting the form would seem pointless when you could make it validate no matter how it is submitted. If there are multiple submission buttons it would also be beneficial to use onsubmit so as to put as much code in one place as possible.
-
September 5th, 2007, 01:49 PM
#9
Re: Very strange problem in firefox
Originally Posted by davidc2p
1- Always a good practice to quote what kind of script you are calling even if implicit.
All scripts are already declared in the <script> tag. To state it again is useless.
Originally Posted by davidc2p
2 - the initial program is using an INPUT type image.
But an input type image acts just like a submit button. If you click it then the onsubmit function fires.
Originally Posted by davidc2p
3 - onsubmit is a very limited event, always try to manage your submission yourself, you will deal with a much larger range of possibilities.
The onsubmit event is no different from any other JavaScript event. It is not limited any more than onclick is!
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|