textbox.width=textbox.width*0.85 Text Resize Control Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeanJo
    New Member
    • Nov 2007
    • 6

    textbox.width=textbox.width*0.85 Text Resize Control Help

    I am trying to develop a resize module i can include on my pages that calculates the size of input fields based on the screen resolution...
    I can already detect the screen resolution, and i have the width / height multiplier for every resolution i need to support... my problem is this...


    I want the include file to be totally universal so heres my plan
    I will use CSS styles to set the current text box size... i want the javascript to then detect the screen size and apply the correct multiplier to the textbox size...

    Where i run into issues is getting the current textbox size and adding it to itself, it seems i cannot use the current textbox size because the javascript is loading before the text boxes themselves...

    I am triggering this java on the BODY ONLOAD event....

    [CODE=javascript]frmMain.txtLogi n.style.width=f rmMain.txtLogin .style.width*in tWidthMultiplie r[/CODE]

    the input box would be coded like this

    [HTML]<input type=text name=txtLogin style="height:2 0; width:200; font-size:12" />
    [/HTML]

    Thanks in advance for any help you can add.
    Last edited by gits; Nov 30 '07, 10:35 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    welcome to TSDN ...

    in case you call the script onload the textbox is ready to use and to be manipulated ...

    but i think you have to add units to the width-value ...

    [CODE=javascript]text_box_refere nce.style.width = your_width + 'px';[/CODE]
    note: the retrieved value should have that unit already, so you have to strip the value out of that before using math-operations :)

    kind regards

    ps: you should add the units too in the elements style-declaration ...

    Comment

    • DeanJo
      New Member
      • Nov 2007
      • 6

      #3
      Im not familiar with units i will have to research these, i am executing the java function on Body Onload, when i try to use this code

      Code:
      frmMain.txtLogin.style.width=frmMain.txtLogin.style.width*intWidthMultiplier
      then it errors stating "Invalid arguement"

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        have a look at the following example:

        [HTML]<script type="text/javascript">
        function resize_tb(tb_id ) {
        var tb = document.getEle mentById('my_tb ');
        tb.style.width = tb.style.width. replace(/px$/, '') * 2 + 'px';
        }
        </script>
        <body onload="resize_ tb('my_tb');">
        <input style="width:40 0px" type="text" id="my_tb" name="test" value="test"/>
        </body>
        [/HTML]
        the invalid arg error should come from another line of your code since the one you posted has no arguments?

        kind regards

        Comment

        • DeanJo
          New Member
          • Nov 2007
          • 6

          #5
          for(i=0; i<document.frmM ain.elements.le ngth; i++)
          {
          if(document.frm Main.elements[i].type=="text")
          {
          document.frmMai n.elements[i].style.width=do cument.frmMain. elements[i].style.width * intWidthMultipl ier;
          }
          }
          }

          I continue to get invalid arguement with this.....
          The error is pointing to this line
          document.frmMai n.elements[i].style.width=do cument.frmMain. elements[i].style.width * intWidthMultipl ier

          the variable intWidthMultipl ier during my tests has a value of 0.050

          Comment

          Working...