473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

prototype.js breaking my Javascript

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

Feb 7 '07 #1
3 1784
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

Feb 7 '07 #2
On 7 Feb, 18:25, "David Golightly" <davig...@gmail.comwrote:
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- Hide quoted text -

- Show quoted text -
David

Thanks very much - I'd been looking at it for hours

Now just got to test the other 2000 lines of code in my javascript
file :(

Feb 7 '07 #3
On Feb 8, 3:37 am, mike_solo...@lineone.net wrote:
I am trying to use prototype.js to log javascript errors among other
things but by including
Use Firefox + Firebug, you will find it far more useful for debugging
that Prototype.js, even if your target is IE only.

<URL: https://addons.mozilla.org/search.php?
q=Firebug&type=E&app=firefox >
>
<script type="text/javascript" src="prototype.js"></scriptin my
page some of my existing javascript no longer works
Prototype is not name-spaced, you likely have a conflict with some
other variable with the same name. I don't know enought about it to
say where off the top of my head and I don't feel like trawling
throught its few thousand lines of code to find out. :-)
>
for example

function submitAction(form,newaction,hiddenName,hiddenValue ) {

form.action=newaction;
//alert(mike.ADMUSER.value);

for ( i in hiddenName) {
It is a very bad idea to let counters slip into the global space,
always declare variables with var unless you have a good reason not
to.

for (var i in hiddenName) {

Also, before version 1.5, Prototype.js extended Object, so you might
be having trouble here. In version 1.5, Prototype itself started to
use for..in so it no longer extends the built-in Object object.

[...]
>
Can anyone explain why this gives me a Javascript error
If it all works without Prototype.js then I'd advise you to not use it
and find a better behaved library. If you say what you are primarily
using it for (other than debugging) you might get some suggestions.
The Yahoo! UI stuff is pretty good, but might be a bit big for what
you are doing:

<URI: http://developer.yahoo.com/javascript/ >
--
Rob

Feb 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Elf M. Sternberg | last post by:
One of the complaints about prototype.js (google for it if you're not familiar with it) is that it's poorly documented. I have this inkling that the key to understanding prototype.js is in the...
1
by: Catherine Jo Morgan | last post by:
I get the point of backing up the database I'm working on, but what's a prototype copy? How do I make one and why is it important to work on that rather than on the main database? Or is this more...
4
by: jemptymethod | last post by:
http://htmatters.net/htm/1/2006/01/EIBTI-for-Javascript-explicit-is-better-than-implicit.cfm
11
by: shypen42 | last post by:
Hi all, I'm very confused by the relation between "prototype" and that "Prototype.js" library that seems to be used quite a lot (not by knowledgeable people from this group if I understood...
28
by: Diodeus | last post by:
I would like to set up an event observer outside of an object, so I can't use this.bindAsEventListener. How can I pass the correct object reference? I tried something like this, and various...
8
by: Chad Burggraf | last post by:
Hi all, I'm brand new to this newsgroup. I've been reading the FAQ's and some other documentation submitted by regulars of the group (such as "Javascript Best Practices" at...
3
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: ...
7
by: jangchoe | last post by:
I've heard that JavaScript is a prototype-based language instead of a class based one. I'm interested in learning the prototype-based paradigm of OO programming, but I am unsure of the best way to...
83
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.