Jump to content

Listbox ... java...Help?

Recommended Posts

Ok, I might be in the wrong place, pardon if I am.  It's been awhile since I coded anything let alone Java and I need a real quick refresher.

Quick outline: Online Monthly newsletter.  I want user to select Year and month, and display type then hit submit button which will then open a new window with the corresponding Newsletter in the corresponding format. These are all 1 page html documents.

Listbox1 has the months, listbox2 has the years.  Button1, Button2, Button3 are Show as PDF, Show as Word, Show in Browser respectively. 

Filenames are Month Year Newsletter.EXTension

So it should be something like: 

function myFunction() {
    var x = document.getElementById("frm1");
    var text = "";
    var i;
    for (i = 0; i < x.length ;i++) {
        text += x.elements[i].value + "<br>";
    document.getElementById("demo").innerHTML = text;

but this is not on a form, would it be easier to create a form? I just have them as listboxes on a page.  Like I said, I can do it, just rusty. 


Link to post
Share on other sites

You don't need a <form> element, but you will need form controls. Start by setting up your inputs

<select id="months">
  <option value="January">January</option>
  <option value="February">February</option>
  <option value="March">March</option>
  <option value="December">December</option>

<select id="years">
  <option value="2000">2000</option>
  <option value="2001">2001</option>
  <option value="2002">2002</option>
  <option value="2018">2018</option>

<select id="extension">
  <option value="pdf">Show as PDF</option>
  <option value="doc">Show as Word</option>
  <option value="html">Show in Browser</option>

<button id="go">Open</button>

Your script needs to access the button and the inputs using document.getElementById(). When the button is clicked, combine the values of the inputs into the name of the file. You should also specify the path of the file in the resulting string. Once that's done, you can use window.open() to open the document in a new window, or location.href to open it in the current window.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...