|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello
I have a file on my local drive (BMIStandard.htm) which contains the following: <form onSubmit="document.forms[0].elements[2].value=(document.forms[0].elements[1].value/2.2)/(document.forms[0].elements[0].value*0.0254* document.forms[0].elements[0].value*0.0254); return false;"> When I save the file onto the server, it changes this code to <form onSubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1"> why is this happening, and is there an easy solution? |
|
#2
|
||||
|
||||
|
I think that Frontpage will rewrite your code sometimes. I've had similar issues when using the WYSIWYG editor in the past.
|
|
#3
|
||||
|
||||
|
remove FrontPage from your computer and it won't happen.
and I hope you're aware that such code as you posted is top-level bad code? very messy, very prone to errors, very hard to change/understand. |
|
#4
|
||||
|
||||
|
Quote:
Hmmm, validates okay though ![]() ...Except for the "language" attribute for the <form> element. I'd also like to add that FrontPage 2003 isn't anywhere near as bad as its predecessors... it now support XHTML 1.0 Transitional and has a cool tag display bar... more powerful than Dreamweaver's. Still, no support for code collapsing/outlining nor individual tag coloring.... thats the only real reason why I use Dreamweaver over VisualStudio thesedays |
|
#5
|
||||
|
||||
|
anything that mess with my code and change it without me knowing it is very bad and I'll never use such thing unless I'm forced to.
I refered to this code as being written badly: Code:
onSubmit="document.forms[0].elements[2].value=(document.forms[0].elements[1].value/2.2)/(document.forms[0].elements[0].value*0.0254*
document.forms[0].elements[0].value*0.0254); return false;"
yeah, it may work but on the other hand it may not work - and then you're stuck - studying such code is pure horror! |
|
#6
|
|||
|
|||
|
would you perhaps be able to suggest some alternative code then? that is not so horribly bad?
I suppose I will just copy paste the code into a notepad and save it that way. Thank you |
|
#7
|
||||
|
||||
|
Well, the whole concept of inline JavaScript is a bad idea... except for smaller things, such as event-handler function calls.
And IRT FrontPage.... SW: I was referring to FP's code-view, which isn't too bad. However, some parts of FrontPage, including HTML generated by "WebBots" == baaad HTML ...Hence why I use my own custom and user controls in ASP.Net ph33r ![]() |
|
#8
|
||||
|
||||
|
Quote:
um... yes - have the onsubmit call javascript function, and in that function have lines, for god sake! inline javascript was never meant for such uses. Quote:
fear?? what a name is that? ![]() |
|
#9
|
|||
|
|||
|
you know, there really isn't any need to be mean, just because I'm not very good at programming doesn't mean I'm stupid. If you don't want to help just don't reply to the post.
Thanks |
|
#10
|
||||
|
||||
|
Naw.... Use it in this context:
"ph33r my 3vil l33tness!" I've even got the official Megatokyo T-Shirt in my wardrobe! |
|
#11
|
||||
|
||||
|
Quote:
sorry, now I understand I was offensive. it's not much bad programming as it's bad progamming habit - excellent code can be written all in one line and work like a charm and be written by the best programmer in the world. the problem is what if somebody else need to read the code and change it? or even you, after a while? so, in my opinion, good programming habit is having the code written line by line, in organized steps. of course you can make shortcuts here and there, but such line of code as the one you have is way beyond shortcut. bottom line, replacing your code with something like the below code is what considered by me better programming habit - but it's only my opinion. if the code works and you can change/understand it without any problems, nobody can argue. Code:
<script type="text/javascript" language="javascript">
function FormSubmit()
{
//get values:
var value1 = document.forms[0].elements[1].value/2.2;
var value2 = document.forms[0].elements[0].value*0.0254;
var value3 = value2*value2;
...
document.forms[0].elements[2].value = value1/value3...
return false;
}
</script>
<form onSubmit="return FormSubmit();">
this isn't good yet - instead of using the index of each element, you better use name: what if in the future you add form element or change their order? you'll stumble into weird errors in the calculation. and also, giving meaningful names to the variables is very important for understanding the code later. just hope to give you some programming tips - hope it's more clear now... ![]() Last edited by Shadow Wizard : January 12th, 2005 at 02:56 PM. |
|
#12
|
|||
|
|||
|
fabulous! hehe. I changed it to include variable values...looks good, works good.
Thanks! |
|
#13
|
||||
|