Search code examples
javascriptjqueryhtmllimesurvey

Replacing functionality of one button with the functionality of another button using Javascript


I am using LimeSurvey and I have to change the functionality of a button using javascript.

I have a button with ID "NextButton", and On clicking that I want to call "SubmitButton" and hence the functionality of "SubmitButton" is executed.

I can only do this using Javascript/Jquery a nothing can be done in HTML.

Please let me know if it is possible.

I know it has to do something with OnClick event, but I am not sure how to replace the functionalities like I said.


Solution

  • It is impossible with mere HTML because you cannot process logic with HTML.

    The most easy thing you can do is simulating the click on another button using JQuery:

    Given the following buttons:

    <input type="button" id="action_1" value="Button A" />
    <input type="button" id="action_2" value="Button B" />
    

    You can use something like this:

    <script type="text/javascript">
        $("#action_1").on("click", function() { 
            $("#action_2").trigger("click");
        });
    </script>