locked
Should be easy solution for javascript RRS feed

  • Question

  • User362960214 posted

    It's been a while since I coded anything in HTML or Javascript (function wise).  I have 2 listboxes, Years, Months and 3 buttons, Show as PDF, Show as Word, Show in Browser.  I want a function for when the user clicks one of the buttons it opens a new window with the selected year and month of our newsletter.  Newsletter file names are "Year Month Newsletter.EXTension" (.pdf, .doc, .html)  It should be something like this - 

     function OpenNwsLetterPDF() {
     var sel
    = document.getElementbyId("listbox1");
     var SelectYr
    = sel.value;
     var sel2 = document.getElementbyID("listbox2");
    var SelectMth = sel2.value;
    window.open("/Newsletter/&SelectYr& &SelectMth& Newsletter.pdf");
    }

    So this would be for the PDF button.  Not working though.  HELP!!!

    Monday, February 26, 2018 5:50 PM

All replies

  • User475983607 posted

    I guess you asking how to concatenate in JavaScript?  Assuming year is 2018 and Month is Jan, this code 

    window.open("/Newsletter/" + SelectYr.toString() + SelectMth.toString() + "Newsletter.pdf");

    will produce a URL of 

    "/Newsletter/2017JanNewsletter.pdf"

    If spaces are needed then.

    window.open(encodeURI("/Newsletter/" + SelectYr.toString() + " " + SelectMth.toString() + " Newsletter.pdf"));
    /Newsletter/2017%20Jan%20Newsletter.pdf

    Monday, February 26, 2018 6:09 PM
  • User1400794712 posted

    Hi BLCOffice,

    So this would be for the PDF button.  Not working though.  HELP!!!

    What do you mean with not working?

    1. Nothing happened?
    2. Or like what mgebhard said, the url is not correct? 

    If there is nothing happens, please open F12 developer tools to check if there is anything wrong with the javascript code.

    Best Regards,

    Daisy

    Tuesday, February 27, 2018 6:06 AM
  • User362960214 posted

    I don't get a 404 error, so it's not even reaching the open window section of the code.  Since it's been so long since I coded java, I'm not sure I'd catch a syntax error.  

    When I select in both listboxes and click the button, nothing happens, no error, no new window.  First off, I need to error trap if someone hasn't selected something in BOTH boxes.  I am total crap at error trapping so any help there would be appreciated. 

    Tuesday, February 27, 2018 2:32 PM
  • User1400794712 posted

    Hi BLCOffice,

    BLCOffice

    Since it's been so long since I coded java, I'm not sure I'd catch a syntax error.  

    I've tried your js code and find that:

    document.getElementById("listbox1")

    Not

    document.getElementbyId("listbox1")

    Please note the case.

    You can check your js code in Browser Console:

    Best Regards,

    Daisy

    Wednesday, February 28, 2018 6:24 AM