This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on problem with addEvent

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're using mootools and I am new to mootools and I'm trying to change the color of a button based on 2 or more checkboxes clicked on my form. I can get the code to work in jsfiddle however I am working in the Oracle Workshop IDE using weblogic server (don't know if this makes a difference and thought I'd better state the environment).

The problem is the addEvent("click", function(ev) {... is not working. I can get alerts prior to this event in the code I just can't get an alert after. If someone could please take a look at my code below perhaps another set of eyes could find what my problem is. Any help/direction would be appreciated. Regards.

Here is my HTML code:




Here is my JS code:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ARe you sure that optionCheckboxes is returning results? Check the length.

Is there a reason why you do not use $$?

Eric
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I added an alert ("optionCheckboxes value " + optionCheckboxes); PRIOR to the addEvent("click", function(ev)... I get nothing not even a null value.

In my same code in jsfiddle, I get "optionCheckboxes value: [object Object]"

I'm not sure why I'm getting back an empty value within my app. The checkboxes are not suppose to get checked at this point as the page is just loaded.

I'm also not sure what is in the Object above. I look into that.

As far as the $$, can you elaborate on where I would be using that? Again, any help/direction would be appreciated as I'm new to mootools.

Thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, you should really be using the browser's built in console to debug your JavaScript. It is better than using alert.



Are you getting any elements?

Eric
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got back a 0
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well looks like your program is changing the names. View the page source, are the names what you expect?

Eric
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jsp page where I added these checkboxes is nested I think the js file may NOT be viewed by the page in some form or another.

Sorry. I just found that out. I appreciate your time and help.

Regards.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the checkboxes are in the html, the JavaScript should be able to access them. You say that the first alert appears which means it is being called.

What does nested mean? Is it using frames/iframes?

I do not code MooTools, I just know the basics from using it a long time ago, but I would expect the code to look more like this

Basic idea


I used named functions instead out of habit.

Examples
Like you way with name http://jsfiddle.net/5hPbV/
Using a class instead of a name http://jsfiddle.net/5hPbV/1/


Eric

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic