Selecting a Text Field on Page Refresh

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemricc2
    New Member
    • Jan 2008
    • 1

    Selecting a Text Field on Page Refresh

    I have the following simple page. I need to select the BARCODE text field everytime the page refreshes. I know this is pretty basic, but I'm just starting with Javascript. Thanks for the help.

    [HTML]<head>

    <meta content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema">
    <LINK href="css/radevice.css" type="text/css" rel="stylesheet ">
    <script language="JavaS cript" src="/scripts/URLhandle.js" type="text/javascript"></script>
    <script language="javas cript" src="/scripts/refresh.js" type="text/javascript"></script>
    <script language="javas cript">
    </script>
    <SCRIPT LANGUAGE="JScri pt">
    </SCRIPT>

    <meta http-equiv="Refresh" content="10"

    </head>

    <body lang=EN-US style='tab-interval:.5in'>

    <div class=Section1>

    <h1 align=center

    Line:3

    </h1>




    <table>


    <td align=center><F ONT SIZE="4">
    Line:3
    </td></tr>

    <td align=center><F ONT SIZE="4">
    <form action="/rokform/WriteLogixTags" method="GET">
    Pick Status:
    <input type="hidden" name="redirect" value="/user/Web/HH.asp">
    <input type="hidden" name="numtags" value="1">
    <input type="hidden" name="t_1_tagna me" value="RB3Board Feedback">
    <input type="hidden" name="t_1_slot" value="0">
    <input type="hidden" name="t_1_type" value="STRING">
    <input type="hidden" name="t_1_displ ay" value="String">
    <input type="hidden" name="t_1_chang ed" value="1">
    <input type="input" name="t_1_value " value="<%ReadLo gixTag("1,0","R B3BoardFeedback ","STRING");%>" >

    </form>
    </td></tr>



    [B]<td align=center width="50%"><FO NT SIZE="4">

    <form action="/rokform/WriteLogixTags" method="POST">
    BARCODE:
    <input type="hidden" name="redirect" value="/user/Web/HH.asp">
    <input type="hidden" name="numtags" value="1">
    <input type="hidden" name="t_1_tagna me" value="RBGEHH1B CR">
    <input type="hidden" name="t_1_slot" value="0">
    <input type="hidden" name="t_1_type" value="STRING">
    <input type="hidden" name="t_1_displ ay" value="String">
    <input type="hidden" name="t_1_chang ed" value="1">
    <input type="input" name="t_1_value " value="<%ReadLo gixTag("1,0","R BGEHH1BCR","STR ING");%>">

    <input type="submit" name="submit" value="Set Value">
    </form>
    </td>
    </table>


    </div>

    <p class=MsoNormal ><o:p>&nbsp;</o:p></p>

    </div>

    </body>

    </html>[/HTML]
    Last edited by gits; Jan 7 '08, 08:21 AM. Reason: added code tags
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    just insert:
    Code:
    <BODY onLoad='document.getElementById("t_1_value").focus();'>
    One tip from a long-time expert: don't use generators for your page, just learn HTML and do it manually!
    Garbage like
    Code:
    <p class=MsoNormal><o:p>&nbsp;</o:p></p>
    is an indicator that you used Microsoft Word or another microsoft-office-product to make this page!
    They are doing nothing except slowing down your page and making modifications very difficult!

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by chaarmann
      just insert:
      Code:
      <BODY onLoad='document.getElementById("t_1_value").focus();'>
      That wouldn't quite work because the ID hasn't been set. If the id of the text field is set to "t_1_value" , it should work as expected.

      Agree with your tip :)

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        Originally posted by acoder
        That wouldn't quite work because the ID hasn't been set. If the id of the text field is set to "t_1_value" , it should work as expected.

        Agree with your tip :)
        But what you said is wrong for IE, I tested it.

        example code, test it yourself.:
        Code:
        <input type=text name="myBox">
        <input type=text onChange="alert('You entered above: ' + document.getElementById('myBox').value)"'>
        It seems that if an element does not have an "id", but a "name", then
        getElementById( ) fetches the element as though the name would be its id.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by chaarmann
          But what you said is wrong for IE, I tested it.

          example code, test it yourself.:
          Code:
          <input type=text name="myBox">
          <input type=text onChange="alert('You entered above: ' + document.getElementById('myBox').value)"'>
          It seems that if an element does not have an "id", but a "name", then
          getElementById( ) fetches the element as though the name would be its id.
          Yes, I know that "works", but it's wrong and buggy. document.getEle mentById() should only fetch an element by its ID as its name suggests, not the element's name. This won't work in any of the other browsers.

          To fetch an element by its name, we have document.getEle mentsByName().

          Comment

          Working...