How to add onfocus to my textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #16
    the textbox isn't very relevant in this case ... we would need to have a look at the surrounding code ... i think the problem is the setting of the display of the divs? i think that such a line:

    Code:
    document.getElementById("leftDiv").style.visibility='visible';
    fails ... and i suppose that "leftDiv" is either not unique or that id is not present at all ... so i asked for the html-code where the divs appear.

    Comment

    • readbanana
      New Member
      • Jul 2010
      • 37

      #17
      Code:
      <div style="display: none;" class="leftdiv" id="leftDiv"></div><input type="text" onblur="Invisible(this)" onfocus="Visible(this)" class="grid-input" id="ctl00_ContentPlaceHolder1_gridUC_summaryGV_ctl03_costTB" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$gridUC$summaryGV$ctl03$costTB\',\'\')', 0)" value="294.00" name="ctl00$ContentPlaceHolder1$gridUC$summaryGV$ctl03$costTB"><div style="display: none;" class="rightdiv" id="rightDiv"></div>

      Comment

      • readbanana
        New Member
        • Jul 2010
        • 37

        #18
        each <td> has the divs surrounding them but they stay display:none. the first divs change to display block

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5388

          #19
          so the id's aren't unique as a already metioned. you should make them unique by adding something unique to them serverside which could be recognized from your textbox - for example its id - so the function on the client could look like this then:

          Code:
          function Visible(obj) {
              var lDivId = 'leftDiv_' + obj.id;
              document.getElementById(lDivId).style.visibility='visible';
          }
          for example.

          Comment

          • readbanana
            New Member
            • Jul 2010
            • 37

            #20
            What would the server side code look like? This doesn't work just like this

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5388

              #21
              i guess the ItemTemplate would need to take care of that - there the div's ids are assigned -> so they would need to be adapted.

              Comment

              • readbanana
                New Member
                • Jul 2010
                • 37

                #22
                I'm not exactly sure what you are saying I should do. The code that you gave me doesn't do anything - my divs don't show up at all.

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5388

                  #23
                  • the id of a node has to be unique in a document - that is the purpose of an id
                  • in your serverside code make it unique (this is probably to do in the ItemTemplate that you posted)
                  • the id should be identifyable by the node that is passed to the Visible() method for example its id - so that the method could then identify the corresponding divs - note that this id in the current shown code would need to be the clientId of the textnode

                  Comment

                  • readbanana
                    New Member
                    • Jul 2010
                    • 37

                    #24
                    I thought that's what (this) passes in.it tells it which textbox it is. how would I know they dynamically given id?

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5388

                      #25
                      don't know asp.net quite well - but i think there is a property called ClientID for a control - which should be the one you might use ...

                      PS: and this is then the object=textbox-node ... but you would need to use a property like the id then ... as shown already
                      Last edited by gits; Jul 26 '10, 06:12 PM.

                      Comment

                      • readbanana
                        New Member
                        • Jul 2010
                        • 37

                        #26
                        I figured it out.I have div, textbox, div. so the div is a sibling of the textbox. Instead of saying leftdiv visible, I made the previous and next siblings of the textbox invisible. Thanx for all your help.

                        Code:
                        function Visible(textbox)
                        {
                        var rightdiv =textbox.nextElementSibling;
                        rightdiv.style.display='block';
                        var leftdiv = textbox.previousElementSibling;
                        leftdiv.style.display= 'block';
                        }
                        function Invisible(textbox)
                        {
                        var rightdiv =textbox.nextElementSibling;
                        rightdiv.style.display='none';
                        var leftdiv = textbox.previousElementSibling;
                        leftdiv.style.display= 'none';
                        }

                        Comment

                        Working...