3 Replies Latest reply on May 12, 2010 10:05 AM by satrapu

    s:button vs. onclick

    dahm

      Hi,


      s:link and s:button behave differently if you add an onclick parameter.


      This is because s:button is rendered with it's own onclick code, which doesn't regard the onclick code. I.e. it is overwritten.
      In my case I'd just like to display some confirm box as in



      s:button action="#{listAdminsForm.deleteAdmin}" onclick="javascript:if(!confirm('Do you really want to delete this entry?')){ return false; } else { return true; }">
      <f:param name="userId" value="#{admin.id}" />
      </s:button>




      This works for fine s:link.


      Is there any workaround or better way to do this?


      Cheers
        Markus.

        • 1. Re: s:button vs. onclick
          christian.bauer

          Use s:link and style it as a button with CSS. Many buttons on this website are s:link.

          • 2. Re: s:button vs. onclick
            keithnaas

            I couldn't agree more with Christian.  On apps I've worked on, we avoid buttons at all cost since links work so well (and links are easier to style since IE doesn't let you control much of the look of a button).

            • 3. Re: s:button vs. onclick
              satrapu

              I know this is an old post, but I encountered the same problem.
              I just wanted a simple javascript confirmation box - if the user clicks OK, perform the action, otherwise do nothing.


              Here is my solution for the s:button:



              <s:button value="Cancel" action=#{myBean.doCancel} onclick="if(!confirm('Are you sure ... ?')) return false;"/>





              You do not need to add if(!confirm(...)){return false;}else{return true;}.