On Feb 7, 9:37 am, mike_solo...@lineone.net wrote:
I am trying to use prototype.js to log javascript errors among other
things but by including
<script type="text/javascript" src="prototype.js"></scriptin my
page some of my existing javascript no longer works
for example
function submitAction(form,newaction,hiddenName,hiddenValue ) {
form.action=newaction;
//alert(mike.ADMUSER.value);
for ( i in hiddenName) {
var x = form[hiddenName[i]]
x.value = hiddenValue[i];
}
//form.submit();
alert(x.value)
}
This is called in the page like so:
<form name="main" method="post">
<a href="#" onClick="submitAction(document.main,'menuforms.php ',
['EVENT'],['bttf07'])">BTTF</a>
<input type="hidden" name="EVENT">
</form>
Can anyone explain why this gives me a Javascript error
Thanks
Well, first off, your "this gives me a javascript error" is not
especially helpful. Could you elaborate on what the text of the error
is? If you're developing using IE, chances are you aren't going to
get meaningful error messages to begin with; pick up Firefox and
Firebug.
Second, your syntax is incorrect for what you actually want. You're
treating an array like an object:
for (i in hiddenName) {} // this will iterate through all of an
object's properties; if you pass it an array it will iterate over its
enumerable items as well as added properties and methods
for (i=0; i<hiddenName.length; i++) {} // this is what you want: only
iterate over the object's enumerable properties
The reason why Prototype exposes this incorrect syntax is because it
adds properties to the built-in Array object's prototype like so:
Array.prototype.flatten = function() { /* code */ }
Try entering this code in the address bar of your page running
Prototype.js and it should all make sense:
javascript
:var s='', a=[1,2,3];for (var n in a) { s += n+':'+a[n]
+'\n'; } alert(s);
David