SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto-select a form field

    Hi,

    I'm working on part of an intranet system that accepts payments. The system is within a frameset (not my choice), and there's a page called swipecard.php in the frame "main". I've setup a magnetic stripe reader so that when a card is swiped, the data from it is pasted into a text form field and it automatically sends a carriage return to submit the form.

    My problem is that when the page loads, the text form field is not selected (despite using tabindex="1"). This means that the user has to click in the text field in order for the flashing cursor to appear, and for the data to get sent to that field. I'm guessing that the only way to automatically select the text field within the frame so that it's usable, is using JavaScript.

    Does anyone know how I could achieve this?

    Thanks,

    Rob


  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure. Show us the code for that form please.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by Kravvitz
    Sure. Show us the code for that form please.
    Here you go:
    HTML Code:
    <form action="****.php" method="post" enctype="multipart/form-data" name="form1">
      <div align="center">
        <p>
          <input name="textfield" type="text" class="dispatch_form" id="textfield" tabindex="1">
    </p>
        <p>&nbsp;</p>
        <p>
    <input name="in" type="submit" class="dispatch_form" value="Button 1">&nbsp;&nbsp;&nbsp;
    
    <input name="out" type="submit" class="dispatch_form" value="Button 2"></p>
        <p>&nbsp;</p>
        <p>&nbsp;    </p>
      </div>
    </form>
    Thanks


  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script it this long so that it won't mess up any other scripts that you may have running in that document.
    The required pieces are in bold.
    Code:
    <script type="text/javascript"><!--
    var tempFunc;
    if(typeof window.onload == "function") {
      tempFunc = window.onload;
    }
    window.onload = function() {
      if(typeof tempFunc == "function") tempFunc();
      document.form1.textfield.focus();
    }
    // -->
    </script>
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for that, I'll give it a go.


  6. #6
    SitePoint Guru
    Join Date
    May 2004
    Location
    santa rosa, ca
    Posts
    969
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tester, I'm interested in how you take information from a magnetic card reader? Can you please share any information or code that does this?
    nondenominational, noncommercial, nonprofit,
    listener-supported, 24-hour, Christian ministry:
    Listen Live Online


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •