0

I have a click function in jQuery and it never seems to execute. I need another pair of eyes:

The ASP button:

<asp:Button ID="btnSubmit" runat="server" Text="Transfer" CssClass="btnSubmit" Enabled="false" />

The Javascript/jQuery

$(".btnSubmit").click(function () {

    var count = ticks.length;
    var x;

    for (var i = 0; i < count; i++) {
        if (ticks[i].Symbol == pair) {
            x = $(".txtAmount").val() * ticks[i].Ask;
            if (x != null || x != 0) {
                $(".txtResult").val() = "=" + x;
            }
        }
    }

});
8
  • What does the rendered markup look like? Are you getting any errors? Commented Jun 20, 2012 at 21:26
  • 2
    Does a disabled button still fire a click event? Commented Jun 20, 2012 at 21:27
  • 1
    The button is disabled though... Commented Jun 20, 2012 at 21:28
  • I remove disable still same result. Commented Jun 20, 2012 at 21:29
  • 2
    Chris is correct. jsfiddle.net/NAUbk It is disabled so it will not fire the event. Commented Jun 20, 2012 at 21:29

4 Answers 4

1

Step 1: replace your click function with:

$('.btnSubmit').click(function(){
    alert('works');
});

If you get an alert, there is something wrong with all that internal code. Can't help you much there since it has a bunch of variable and class names you haven't showed us.

If it doesn't work... maybe issues including jQuery properly?

Anyway, those are just the steps of debugging. Simplify your code to rule out portions/lines and add back in functionality until it breaks. The last thing you added is what is broken.

Sign up to request clarification or add additional context in comments.

3 Comments

yeah the alert doesnt work at all, I have .change working which is odd from jquery sigh no idea whats causing it fireebug and ie javascript debugger doesnt show anything.
If you can provide a bit more of your code, I may be able to help more. But if the click event isn't even firing (and it's not because the button is disabled per the comments on the question), there's gotta be something else going on.
instead of .click I am using onclick= instead on an input field.
1

Is your "txtResult" element a textbox? You cannot assign a value to a textbox like you are here:

$(".txtResult").val() = "=" + x;

You would need to do this:

$(".txtResult")[0].value = "=" + x;

Small example: http://jsfiddle.net/wqZmv/

Otherwise I would need to see more of the code if it is a different issue.

1 Comment

I ended up doing: $(".txtResult").val('item'); and var item = "=" + x; Seems to work for me
0

Seems as if there is an issue with Umbraco if someone could clarify why this might be I would be greatful.

For now my solution involved doing the following:

Replacing <asp:Button ID="MyButton" Text="Transfer"></asp:Button> with <input type="submit" value="Transfer" onclick="calculate()" />

Using simple javascript event over the the jquery event. I can get the jquery to work outside of umbraco.

I replaced asp:Button because I do not need a postback on click, and the input field can do the same job for me.

Comments

-1

Try this:

$("#btnSubmit").click(function () {

var count = ticks.length;
var x;

for (var i = 0; i < count; i++) {
    if (ticks[i].Symbol == pair) {
        x = $(".txtAmount").val() * ticks[i].Ask;
        if (x != null || x != 0) {
            $(".txtResult").val() = "=" + x;
        }
    }
}

});

2 Comments

This will not work because the id of the rendered element is not btnSubmit
I have tried id's but when working with asp.net and umbraco I can't grab the ClientID because umbraco complains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.