Jump to content

Listbox ... java...Help?


JJJorgensen
 Share

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: 

<script>
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;
}
</script>

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 comment
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>

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

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

<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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...