Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Posts
    919
    Plugin Contributions
    2

    Default Attribute File - Update value on page load...

    I'm trying to update the value within an Attribute File edit box on my product pages.

    Instead of having the user specify a file to upload I would like to insert a dynamic path and filename.

    So far I have created an on_load_main.js file within the modules directory for the page in question. This file contains the code below.

    Code:
    document.forms.cart_quantity.id[TEXT_PREFIX5].value = 'test';
    When I reload the page the above code does not work. It appears that id[TEXT_PREFIX5] is invalid (or atleast unknow to the Javascript).

    If I change id[TEXT_PREFIX5] to cart_quantity the quantity box (above the 'Add to Cart' button) is updated. So, I know that the Javascript is being processed.

    Anyone know of a solution?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Attribute File - Update value on page load...

    Two things to note:

    a) if you add more attributes to that product, the "5" may change to a different number
    b) TEXT_PREFIX is a PHP constant. You will have to use its definition of "txt_" instead if you want to use it in a .js file that PHP doesn't process.
    .

    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.

  3. #3
    Join Date
    Mar 2006
    Posts
    919
    Plugin Contributions
    2

    Default Re: Attribute File - Update value on page load...

    Once again, thanks for the speedy reply.

    Could you advise me how to proceed with option b as mentioned in your previous post, please?

    I did have an idea of using Javascript to update the value of all file input fields (as I'll only have one on the page) to work around this. However, I'm not sure if it's possible yet.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Attribute File - Update value on page load...

    document.forms.cart_quantity.id[txt_5].value = 'test';

    vs

    document.forms.cart_quantity.id[TEXT_PREFIX5].value = 'test';
    .

    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
    Mar 2006
    Posts
    919
    Plugin Contributions
    2

    Default Re: Attribute File - Update value on page load...

    It turns out that I can't use Javascript to update the value of this field, due to security issues - which makes sense.

    I've tried to edit the following code in attributes.php within the modules directory.

    From:

    Code:
    $tmp_html = '<input type="file" name="id[' . TEXT_PREFIX . $products_options_names->fields['products_options_id'] . ']"  id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '" /><br />' . $_SESSION['cart']->contents[$prod_id]['attributes_values'][$products_options_names->fields['products_options_id']] . "\n" .
                          zen_draw_hidden_field(UPLOAD_PREFIX . $number_of_uploads, $products_options_names->fields['products_options_id']) . "\n" .
                          zen_draw_hidden_field(TEXT_PREFIX . UPLOAD_PREFIX . $number_of_uploads, $_SESSION['cart']->contents[$prod_id]['attributes_values'][$products_options_names->fields['products_options_id']]);
    To:

    Code:
    $tmp_html = '<input type="file" name="id[' . TEXT_PREFIX . $products_options_names->fields['products_options_id'] . ']"  id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '" value="c:\testing.txt" /><br />' . $_SESSION['cart']->contents[$prod_id]['attributes_values'][$products_options_names->fields['products_options_id']] . "\n" .
                          zen_draw_hidden_field(UPLOAD_PREFIX . $number_of_uploads, $products_options_names->fields['products_options_id']) . "\n" .
                          zen_draw_hidden_field(TEXT_PREFIX . UPLOAD_PREFIX . $number_of_uploads, $_SESSION['cart']->contents[$prod_id]['attributes_values'][$products_options_names->fields['products_options_id']]);
    However, it doesn't appear to be working.

    Can you advise if these code changes are correct please?

 

 

Similar Threads

  1. v150 New Radio Button in Products page doesn't load store value
    By jaheadlee in forum Basic Configuration
    Replies: 0
    Last Post: 26 Jul 2012, 09:46 PM
  2. option value that is a link to a file or page?
    By oberheimer in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 24 Sep 2010, 11:07 AM
  3. Load a js file on ANY page under certain condition?
    By yellow1912 in forum Contribution-Writing Guidelines
    Replies: 2
    Last Post: 1 Apr 2008, 07:11 PM
  4. read only attribute value size too small/ import html in read only attribute value
    By nazzaw in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 22 Jan 2007, 03:49 PM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR