Link to home
Start Free TrialLog in
Avatar of Wigging
WiggingFlag for United States of America

asked on

call javascript on button click

i have this url below
   <a href="javascript:fnSelect('test1');"> Select Signature</a>

how can i do the same but by submitting asp button control?
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

You can do something like this:

<asp:button runat="server" text="Test" OnClientClick="javascript:fnSelect('test1');" id="Button1"></asp:button>
Avatar of Wigging

ASKER

when I do as a link the selection stays selected........but when i do it as a button, it doesnt stay selected.....i believe because of postback

I have this script

<script type="text/javascript">
    function fnSelect(objId) {
        fnDeSelect();
        if (document.selection) {
            var range = document.body.createTextRange();
            range.moveToElementText(document.getElementById(objId));
            range.select();
        }
        else if (window.getSelection) {
            var range = document.createRange();
            range.selectNode(document.getElementById(objId));
            window.getSelection().addRange(range);
        }
    }

    function fnDeSelect() {
        if (document.selection) document.selection.empty();
        else if (window.getSelection)
            window.getSelection().removeAllRanges();
    }
      </script>
Yes, it's because of the postback.

Can you use jQuery?

    $("#button1").click(function () {
        fnSelect('test1');
     });
Avatar of Wigging

ASKER

where do i add that code?
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial