1

I want to run a particular javascript when selection is changed in the drop down choice, so I added a simple attribute modifier like this :

ddc.add(new SimpleAttributeModifier("onchange", "calc();"));

But if I do this, it completely overrides the wicket onSelectionChanged() method. I need a way to perform both.

Thanks

Soumitri Pattnaik
  • 3,246
  • 4
  • 24
  • 42

2 Answers2

4

Use an OnChangeAjaxBehavior for this like this:

    ddc.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.appendJavaScript("calc();");
        }
    });
Robert Niestroj
  • 15,299
  • 14
  • 76
  • 119
2

You could use an AttributeAppender

ddc.add(new AttributeAppender("onchange", "calc();", " "));

The last argument is the separator used.

thg
  • 1,209
  • 1
  • 14
  • 26