IHTML Input Element trouble: Cannot determine location inside Value property. RRS feed

  • Question

  • Here's a different one:
    I'm getting IMarkupPointer locations using the Caret position.


    CComPtr<IDisplayServices> pDS;  
    CComPtr<IHTMLCaret> pCaret;  
    CComPtr<IMarkupServices> pMS;  

    Fair enough, except I landed inside the text on a button. It's an Input element. However, I'm inside the value="" property, and the position is based on the beginning of the value="" property.

    To clarify, how my caret ended up in the Input elements value="" property, in the environment, you can double-click the button and edit the value text from the WYSIWYG editor. This puts the caret at an position based on the value="" property, however it doesn't have an element since the search is fried because when you hit '<INPUT', you haven't found a '>' yet. At least that's what I'm assuming.

    How it WAS Dumping:

    I was creating the textrange using the body element and simply moving the textrange to the pointer and getting the text. However it dumped on textrange->get_text(), because the caret is actually INSIDE an element, not within it. Funny that it didn't dump when I moved the Body element textrange to the pointers that pointed INSIDE the Input element.

    Ignoring that, I decided to use the CurrentScope method to get the element instead of using the body element every time. I then get the element type using the Markup Services.

        hResult = pMPbegin->CurrentScope(&pElement);  
        if (S_OK != hResult)  
        if (!pElement)  
        hResult = pMS->GetElementTagId(pElement, &eTagId);  
        if (S_OK != hResult)  
        switch (eTagId)  
            case TAGID_BODY:  
                CComPtr<IHTMLBodyElement>   pBodyElement;  
                if (!pBodyElement)  
                hResult = pBodyElement->createTextRange(&pTxtRange);  
                if (S_OK != hResult)  

    What doesn't work NOW:

    However, since I'm inside an Input element, it doesn't return an element, it returns NULL. Normally, this allows me to get the text at the cursor anywhere but the value of Input elements (button type). It basically keeps me from getting to the point where I dumped before.

    I'm wondering, however, how I can determine I'm inside the value="" text of an input element using the IMarkupPointer I have based on the Caret.

    I tested using the IMarkupPointer2, and found out the position is based on the beginning of the value="" property. So, this totally fries the possibility of moving around and looking for that input element, as far as I know.

    So currently, I cannot get_text from the value of the Input element I'm inside of, because I can't tell I'm inside an Input element. If I can get the Input element, I can retrieve the value text and use the offsets from the IMarkupPointer2 I can create from the IMarkupPointer I already have. Then I can substring out the text I want. However, CurrentScope() doesn't return the Input element when I check for it.

    I don't see anywhere how this could possibly be handled. I've researched the IHTML services for weeks now trying to learn how this all works.


    It's all a Nemesis plot.... No really!
    Tuesday, December 2, 2008 9:44 PM

All replies

  • I see that the language you are using is C++. Do you have a VC question? I am asking since I seem to have missed the question.

    If your question is about the DOM and such, then that is supposed to be asked in a forum that includes that subject. I do however understand how difficult it is to find a forum that has good help about the DOM. I hope you do get help, whether here or elsewhere.

    If you can simplify and/or clarify your question then it will be easier for someone to help.

    Sam Hobbs; see my SimpleSamples.Info
    Wednesday, December 3, 2008 3:37 AM
  • My markup pointer is located within the value text of an Input element (it got there because it's based on my caret location) (my caret got there because I'm WYSIWYG editing the caption on a button).

    You cannot get text from this range because it is WITHIN the brackets (<, >) of a tag. HTML services ignores "text" within a bracket, so I'm at an invalid location for get_text().

    How can I, using a markup pointer inside an INPUT element's brackets, know I'm in an INPUT element and get the value of the field?

    Once I have the value of the field, I can use IMarkupPointer2 to get the offset within the value, because inside the value property of an INPUT element, the offset is based on the starting location of the value property within the HTML code. So I can use the difference between the offsets and substring out the word I need.

    Here's a visual.

    <INPUT type=button value="A word is [p1]here[p2]">

    If you try to create a text range using the Body element or any other containing element and get_text() on the range.... it dumps. This is because you're not at a valid text location. It just doesn't make sense in the element model. Getting the html text dumps also.

    Now.... if I could find out I'm inside the INPUT somehow, I could do this.

    1. Cast the containing element to INPUT.
    2. Cast [p1] and [p2] to IMarkupPointer2. Get the location.

    (it counts the " as a character when getting the location. I think it may even start at v in value, but I don't remember)
    [p1] location = 12
    [p2] location = 16

    3. Get the value of the Input element.


    4. Substring out the word I want.

    CString strFinalAnswer = CString(bstrString).mid(12, 16 - 12);

    This is the only way I  can think to do it, but I don't know how to find out if I'm inside the brackets of an element.

    It's all a Nemesis plot.... No really!
    Wednesday, December 3, 2008 3:44 PM