
Originally Posted by
rhawk6012
The code works in IE but not in Netscape. What am I doing wrong?
You're using some of Microsoft's proprietary nonsense.
In IE, you can access elements using the value of a name or id attribute. However, this is entirely non-standard and, in my opinion, a terrible feature.
In your specific case, it's extremely easy to solve. I've produced a quick-and-dirty solution that shows the basics, but would probably require some alterations. I'll walk through the code you posted, making some comments and drawing some comparisons.
Please understand that Java is very different from Javascript. They are different languages developed by different companies.
In the code I posted, I passed an argument to the validation function. This argument contains a reference to the form, making it much easier to access the controls. Notice the call:
HTML Code:
<form ... onsubmit="return validation(this);">
When the this operator is used within listeners, it refers to the element - the form in this case.
if(custname < 1 || custaddress < 1 || custcity < 1 || custzip < 1 || custdate < 1)
OK, that makes no sense. More importantly, it will fail to validate the entries properly. When a relational comparison (less-than/greater-than) is performed between a number and a string, the string is coerced to a number and then the comparison continues as normal. In most cases, the strings will be converted to NaN (not-a-number) which will result in a value of false for the comparison.
The validation of user input should be performed using regular expressions. I included several simple regular expressions in the demo.
<FORM METHOD="POST" action=mailto:customerservice@alliedrecycle.com name="MyData" ENCTYPE="text/plan">
A couple of things here. The first is that your content type is wrong: it should be text/plain. The second, and more important point, is that forms which use the mailto: scheme are very unreliable. Forms are meant to send content to processing scripts. You should use one to e-mail the content. Your host should provide one, but if not you can find services for free on the Web.
The pre element is meant to be used with source code or program output. That is, text which has already been laid-out. It should not be used to align elements. Use CSS to position elements instead (as per the demo).
<input type=button value="Send" onclick="SendMail()";>
That semicolon is in the wrong place. I'd also like to reiterate that it's better to validate forms based on the submit event, rather than on the submit button.
You didn't close the font element after this closing tag. However, you should be aware that the font element has long been deprecated in favour of style sheets. CSS provides a much richer way of formatting and laying-out HTML documents.
Hope that helps,
Mike
Bookmarks