Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Using jscript onload to focus on input box with constantly varying name

    Yes, using [0] grabs the first element.
    My test site has the Add Selected button at the top of the form, so must have been seeing that button as the first element, thus I had to use [1] for it to work here.
    Adjust as needed, of course.

    niccol's approach is good if you have farther-reaching needs for doing additional customization.
    And his jQuery suggestion is also good ... if you're already using jQuery. If you're not, then it's needless overhead to add it just for that.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  2. #2
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Using jscript onload to focus on input box with constantly varying name

    Well, having thunder stolen by Dr Byte is no bad thing It is just a question of how you target that particular element in javascript. It suits me to do that with a hard coded id rather than navigating through the DOM, as this may actually change as the site is developed, but that is just my way of doing things.

  3. #3
    Join Date
    Feb 2011
    Location
    Indianapolis, IN
    Posts
    38
    Plugin Contributions
    0

    Default Re: Using jscript onload to focus on input box with constantly varying name

    One last question to finalize my quest for streamlining inventory updates. Using the above-mentioned DOM method, I was able to make the "search" box in the admin-->categories.php focus as follows:

    Code:
    onload="init(); document.forms['search'].elements['search'].focus();">
    I had planned to highlight the quantity box in the product listing the same way, which worked except that the iframe with the FCKeditor kept stealing away the focus. I couldn't figure out how to make that stop happening.

    Then, once you move onto the "preview" page, I wanted to set focus on the "update" button so all we had to do is hit "enter" to confirm that we wanted to update. I don't understand the difference between boxes and buttons, but the update button would not respond even focused with "document.NAME_OF_FORM.name_of_button.focus()" in the onload for the page. (I did ensure the input element had a name by changing code in preview_product.php).

    I was hoping to streamline our most common task which is selecting a product and quickly changing the quantity for inventory with simple text inputs and "enter" keystrokes instead of always having to move the mouse after each page advance; the boxes and buttons could be focused and "ready" to receive the data.

    As always, any help is appreciated, particularly with focusing on a button element instead of a box element -- I've almost got that nailed down on "preview."

    Jason

  4. #4
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Using jscript onload to focus on input box with constantly varying name

    As far as the FCKeditor goes, set your default preference for the editor to plain-text, and then the FCKeditor won't even fire. You can always temporarily override that by choosing from the pulldown before clicking on a product.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Feb 2011
    Location
    Indianapolis, IN
    Posts
    38
    Plugin Contributions
    0

    Default Re: Using jscript onload to focus on input box with constantly varying name

    Didn't even realize there was a drop down to choose! Yes, that makes a difference, thanks.

    On the submit button focus issue, I've solved it well enough for now by doing the following:

    It seems that the button is actually created by the function zen_image_submit. I'm not sure how the parameters work together, but I did notice that in the back button above the below code, it included a name="back". In preview_info.php around line 157:

    Code:
    if (isset($_GET['pID'])) {
            echo zen_image_submit('button_update.gif', IMAGE_UPDATE, 'tabindex="1"');
    To the "update" button, I added the 'tabindex="1"' portion in place of what was the 'name' element from for the back button. When the code is drawn on the page, the tabindex in fact allows you to press tab ONE time and it will activate the correct submit button. The onload focus() referenced above did not seem to want to activate the input image submit button. I suspect if that button was a true input type="submit" button it may have been a different story, but I'm not about to go around changing those sorts of things. This is the only instance I'm truly interested in.

    The only way it could be better now is if the submit button were highlighted without having to hit tab, but I am never the less delighted in how this will streamline basic quantity changes to our inventory!

    Jason

 

 

Similar Threads

  1. v139h How to remove focus on Contact Us - Full Name field
    By davidmorrisuk in forum General Questions
    Replies: 2
    Last Post: 7 Nov 2012, 05:32 PM
  2. left box content font size varying between ie and firefox
    By bonnit in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 3 Jan 2011, 10:02 AM
  3. Setting a quantity discount with items with varying attributes?
    By xtina in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 19 May 2010, 12:08 AM
  4. Extra 'input' box needed on product info input page
    By abaris in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 1 Apr 2009, 03:40 PM

Posting Permissions

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