Obviously this isn't the final form, but a snippet I created to debug the form. It still has the same error as the final form. I've been working on this one for hours.
No other javascript in any other html form on my client localhost does this. This is in a MAMP environemnt on a MAC.
It's just here and I can't get fix it to save my a**. Advice most wele at this point. It's got to be something simple. I've tried all the hard stuff and it has no effect on the oute.
html file contents
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>NCSA Contact Form</title>
</head>
<body>
<form action="test.js" name="frmNcsa" id="frmNcsa" method="post">
<input type="submit" name="submitData" id="submitData" value="Submit"/>
</form>
<script type="text/javascript" src="test.js"></script>
</body>
</html>
test.js file contents
var $ = function(id){
document.getElementById(id)
}
function prepareEventHandlers() {
alert("This is test.js")
}
window.onload = function () {
prepareEventHandlers();
}
Firefox Error Message
The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
After Page Reloads
What I see in the browser after clicking the form submit button Page reloads, submit button gone. The JS file is read into the browser as text
var $ = function(id){
document.getElementById(id)
}
function prepareEventHandlers() {
alert("This is test.js")
}
window.onload = function () {
prepareEventHandlers();
}
What should clicking submit do?
An alert dialog box that says "This is a test".
Obviously this isn't the final form, but a snippet I created to debug the form. It still has the same error as the final form. I've been working on this one for hours.
No other javascript in any other html form on my client localhost does this. This is in a MAMP environemnt on a MAC.
It's just here and I can't get fix it to save my a**. Advice most wele at this point. It's got to be something simple. I've tried all the hard stuff and it has no effect on the oute.
html file contents
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>NCSA Contact Form</title>
</head>
<body>
<form action="test.js" name="frmNcsa" id="frmNcsa" method="post">
<input type="submit" name="submitData" id="submitData" value="Submit"/>
</form>
<script type="text/javascript" src="test.js"></script>
</body>
</html>
test.js file contents
var $ = function(id){
document.getElementById(id)
}
function prepareEventHandlers() {
alert("This is test.js")
}
window.onload = function () {
prepareEventHandlers();
}
Firefox Error Message
The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
After Page Reloads
What I see in the browser after clicking the form submit button Page reloads, submit button gone. The JS file is read into the browser as text
var $ = function(id){
document.getElementById(id)
}
function prepareEventHandlers() {
alert("This is test.js")
}
window.onload = function () {
prepareEventHandlers();
}
What should clicking submit do?
An alert dialog box that says "This is a test".
Share Improve this question edited Oct 4, 2012 at 10:26 raam86 6,8712 gold badges33 silver badges46 bronze badges asked Sep 4, 2012 at 18:16 FreedomRoadPublishingFreedomRoadPublishing 232 silver badges4 bronze badges 5- 3 You are posting to a .js file? That's new to me... – Klaus Byskov Pedersen Commented Sep 4, 2012 at 18:20
- 2 Look at your form tag: <form action="test.js"...> – Ivancho Commented Sep 4, 2012 at 18:21
- @KlausByskovHoffmann:- Thats called wild ideas.... :) – perilbrain Commented Sep 4, 2012 at 18:23
-
1
i don't think it's related to your errors, but shouldn't your
$
function return something? e.g.return document.getElementById(id);
– jbabey Commented Sep 4, 2012 at 18:26 -
Do you want the page to be redirected/reloaded? That is what happens when you submit an HTML form. If you want a from without the redirect/reload, you'll need to bind an event handler to the form's
submit
event that halts submission. – apsillers Commented Sep 4, 2012 at 18:32
1 Answer
Reset to default 3By having action="test.js"
in your form, you are telling browsers that the form should be submitted (posted) to test.js on the server, which doesn't make much sense. Without knowing more about what you are actually trying to achieve, I can only assume that you want the form to be purely handled on the client side, in javascript? In this case, you do not need a form at all. You simply need a submit button with an action that calls your handler function when clicked.