Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2004
    Posts
    764
    Plugin Contributions
    0

    Default HELP! Using Javascript to write to Orders Comments box?

    Hey guys! I need some javascript advice. This works fine under 1.5.7 but no longer with 1.5.8a.

    In 1.5.7, I had some custom buttons on my orders.php page. When I clicked the button, it would auto-populate the Comments box so I could easily send a status message to a customer without typing the same personal message.

    For example, I had a button called "24 Hours" and when I would click it, it would use an onClick Javascript command to auto-populate the comments field with a detailed message (something like, "We are currently processing your order and we expect your items to ship within the next 24 hours.").

    I did this with this simple line of code:

    Code:
    <input type="button" name="24Hours" Value="24 Hours" onclick="javascript:document.statusUpdate.comments.value='We are currently processing your order and we expect your items to ship within the next 24 hours.'">
    However, with 1.5.8, there is now a WYSIWYG editor, and I am not able to figure out how to send the onClick text to that kind of object. Can you help?

    I tried this but it's not working:

    Code:
    <input type="button" name="mybutton" Value="Test"  onclick="javascript:document.statusUpdateForm.comments.value='My example message here'">
    I see the actual form name has changed between versions (from statusUpdate to statusUpdateForm), but I don't know how to access the comments box within that object.

    If I can just figure out how to auto-populate text to the current Order Comments box with a click of a button, I can do the rest.

    Any advice on how to do this?
    - Jeff

  2. #2
    Join Date
    Aug 2004
    Posts
    764
    Plugin Contributions
    0

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    UPDATE: I don't have an answer on this yet.....but in the meantime, I found this module (for 1.5.7) which I will test to see if it works on 1.5.8:

    https://www.zen-cart.com/downloads.php?do=file&id=2222
    - Jeff

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,497
    Plugin Contributions
    88

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    You can always disable the WYSIWHG editor and just use TEXT.

  4. #4
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,239
    Plugin Contributions
    1

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    Quote Originally Posted by Jeff_Mash View Post
    UPDATE: I don't have an answer on this yet.....but in the meantime, I found this module (for 1.5.7) which I will test to see if it works on 1.5.8:

    https://www.zen-cart.com/downloads.php?do=file&id=2222
    Yes, I successfully use this on ZC v1.5.8a - I think I had to just make a slight change after getting PHP Warnings on PHP 8.0 and another change to allow for multiple comments to be added.
    Simon

  5. #5
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,703
    Plugin Contributions
    123

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    Simon, please build a new version from your changes and submit to the Plugins Library. Thank you!
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  6. #6
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,239
    Plugin Contributions
    1

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    Quote Originally Posted by swguy View Post
    Simon, please build a new version from your changes and submit to the Plugins Library. Thank you!
    That'll be fun. Will do.
    Simon

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,703
    Plugin Contributions
    123

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    Your adoption of this orphan is greatly appreciated! The community won't thrive without volunteers.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  8. #8
    Join Date
    Aug 2004
    Posts
    764
    Plugin Contributions
    0

    Default Re: HELP! Using Javascript to write to Orders Comments box?

    First I want to thank all of you who responded. I truly love this community and wish I was as great a programmer as you all!

    I decided to go with my own custom Javascript buttons because 1) I am trying to keep my plugins to a minimum, and 2) this way gives me more control.

    If anyone is interested, I will explain below about what I did and why it works for me.

    What I needed: a way to set an order status AND variable order-related text for my orders. This is important if you have many different messages you send to customers. For example, you may want to say something different to a shipped Download order versus a shipped Physical Item order.

    Or let's say that you have one Order Status that says "Processing"........but that could mean a few different things, depending on the items you sell. For example, I could sell an item I have in my local stockroom, or I could sell an item that takes me 2 days to dropship from another location. Both orders would go into a "Processing" status, but I may want to email two different messages to those customers.

    So I have two BUTTONS: "Processing" and "Processing 24-36". Depending on which button I click, it will set the status to PROCESSING for both, but it will copy to clipboard two completely different status messages.

    Here is an image of what part of my Orders Page looks like, with different buttons:

    Name:  OrderButtons.jpg
Views: 103
Size:  44.1 KB

    How it works:

    1. Press the button you want depending on the predefined status of your order. This will copy to clipboard your predefined text, and also set the status in the dropdown menu.

    2. Paste the clipboard to the textarea box and UPDATE the customer.

    The code is very simple. Create as many buttons as you need with this line of code:

    Code:
    <button onclick="myFunction('2','Hi <?php echo $FirstName[0]; ?>!  Thank you for choosing to shop with us! We are currently processing your order.  We expect your items to ship within the next 24 hours.  We will email you again at that time. \r\rIf you have any other questions please let us know.')">Processing</button>
    The first parameter ('2') is whatever you want the dropdown status to be. In our case (and probably most users), 2 = Processing. The next parameter is the text you want to copy to the clipboard. You can even put in variables like the customer's first name like we do, or anything else you can pass to it.

    Then you simply need this function below your buttons:

    Code:
    <script>
    		function myFunction(status,text) {
    		  document.getElementById("statusUpdateSelect").value = status;  // Set the status
    		 navigator.clipboard.writeText(text); // Copy text to clipboard for pasting
    		}
    </script>
    Again, I am not a very good programmer, but this solution is easy and works for me with minimal changes to the original ZenCart orders.php file.
    - Jeff

 

 

Similar Threads

  1. Comments on new orders?
    By harlyman in forum General Questions
    Replies: 1
    Last Post: 21 Mar 2011, 10:20 AM
  2. Using Javascript Drop-Down Box To Automatically Navigate To Product
    By Fastcar in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 13 Dec 2007, 05:41 PM
  3. Help Changing Order Comments Box to Yes/No Buttons
    By Captain Prozac in forum General Questions
    Replies: 0
    Last Post: 13 Nov 2007, 09:03 PM
  4. Printing Comments Box in Orders
    By quixotica in forum Managing Customers and Orders
    Replies: 2
    Last Post: 3 Oct 2007, 12:23 AM
  5. Prevent duplicate orders by using javascript on confirm button?
    By emtecmedia in forum General Questions
    Replies: 4
    Last Post: 5 Dec 2006, 10:59 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