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

Function toggle does not work

 
dela cruz juan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java Script GURU's


I got this basic form that has a validation procedure when selecting on the 1st selection box the valid table should only appear. I got no problems when selecting "Homeroom" and "Sicience"
even if i change the selection on the two topics it shows the valid table but when I choose "Math", "laboratory", "Diff" and "others" the tables keep appending
downwards. Is there something missing on the scipt?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that code has some problems. Firstly, why the call to eval()?

dela cruz juan wrote:Hi Java GURU's

This is JavaScript, not Java. Big difference.
 
dela cruz juan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, why the call to eval()?

Really not sure cause I'm still trying hard to understand and learn about this,
I believe some of the items on the 1st selection box has a dependent items that should show on selection box of the hidden table,
really hard to explain but it goes something like this example

This is JavaScript, not Java. Big difference.

Sorry if I posted this in the wrong location,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dela cruz juan wrote:
Firstly, why the call to eval()?

Really not sure cause I'm still trying hard to understand and learn about this,

Then why is it there? Did you write it? If so, why? If not, where did this code come from?

If this is code you found somewhere and are trying to use it to learn anything, then stop, delete it, and pretend you never saw it. It's awful.

This is JavaScript, not Java. Big difference.

Sorry if I posted this in the wrong location,

My point was that you asked for help from "Java Gurus" for a JavaScript problem. Java is not JavaScript. Do not confuse them.
 
dela cruz juan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If not, where did this code come from?

yes I did just copied that from some online resource
delete it, and pretend you never saw it. It's awful.

Just tried to delete the eval() line, the behavior just only becomes worst, all of the tables now show upon selecting
you asked for help from "Java Gurus" for a JavaScript problem. Java is not JavaScript. Do not confuse them.

Sorry if I mislead the readers, I just made the correction on the above now
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course itr's not going to work if you just delete a single statement. My point is that whatever that code is doing, it's poorly written and you just forget the whole example.

Now back up 57 steps or so and just tell us what you are trying to do and we can help you write code to do it without relying upon badly-written examples.
 
dela cruz juan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

The form has a 1 table that is loaded by default, the table has a 1st selection box. If I select one item let say "Homerrom" the corresponding homeroom table should be loaded below,
if I change to select "science" then math table should disappear then science table should be loaded. My problem by now is if I select:



there tables just load and the form would never update if I select a new item on the 1st selection box
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you are just trying to hide and show elements based upon a selection? Easy. Especially if you take it one step at a time

What's the first thing you need to do?

OK, I'll help kick-start you by giving you the answer: you must establish an event handler for the change event for the select element. Give that a try and see if you can get an event handler to execute when the value of the select is changed.

Is there any reason that you cannot use jQuery for this? That will make everything much, much easier.
 
dela cruz juan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much on your advises, I'm not familiar yet on Jquery but I'll give it a try on the kickstart that you've mentioned.
I'll keep you guys posted on the result.

thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic