Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I'm trying to do something extremely simple yet can not get it to work.

I need to get the value of a tooltip and compare it to the text that is currently in a textbox. I want to do it in javascript so that I can post a client-side pop up confirm before I send it to the server. I can't seem get the textbox. I've tried using jquery and the title and innertext properties are blank even though when I hit f12, the title and value are there.

C#
function confirmHiredChange(ctrl) {
        debugger;
        var row = $("tr[id=trid]");
        var tbHiredDtm = row.find("input[id$=tbeRecruitHiredDtm]");
        if (tbHiredDtm[0].title != "")
            return true;
        else if (tbHiredDtm[0].value == "")
            return true;
        return confirm('Are you sure you want to update this __?');
    }


this executes onclientclick and returns the confirm. I only want to show if the tooltip was previously not set (string.empty) and text value is set (! string.empty). It finds the textbox but no matter what I do, both properties are defined as "" when I come to tbHiredDtm[0] even though when I hit f12 it shows them.

I know it is something small that I am doing wrong, so if you see it feel free to let me know. Or if you know of a better way let me know that as well.

EDIT: TLDR- Basically how can I, in javascript, get the tooltip value of an asp:textbox ?
Posted
Updated 15-Feb-13 5:20am
v2

In your example (assuming tbHiredDtm is the what you want the title of) :

JavaScript
var title = $(tbHiredDtm).attr("title");
 
Share this answer
 
I think this is what you are looking for...
C#
function confirmHiredChange(ctrl) {
        debugger;
        var row = $("tr[id=trid]");
        var tbHiredDtm = row.find("input[id$=tbeRecruitHiredDtm]");
        if ($(tbHiredDtm).attr("title") != "")
            return true;
        else if ($(tbHiredDtm).val() == "")
            return true;
        return confirm('Are you sure you want to update this __?');
    }
 
Share this answer
 
The problem was that the server creates an ID for the textbox so I can't jquery select by the client ID... unless I do it like this

C#
function confirmHiredChange(ctrl) {
    var tb = $("#<%= tbRecruitHiredDtm.ClientID %>");
    var hireddtm = tb.attr("title");
    if (hireddtm !== "" && hireddtm !== undefined)
        return true;
    else if (tb.val() === "")
        return true;        
return confirm('Are you sure you want to update this __?');
    }

That correctly selects the server created ID for me. Also the === compare is slightly faster as it compares via direct compare.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900