Cannot get target="_blank" to work within <option></option> tags.

Experts,

I have "clickable" text within a dropdown. At this point all links open in the same window. the links within the dropdown are a mixture of .cfm and .pdf pages. It is OK for the .cfm pages to open in the same window, but I need the .pdf pages to open in a new window. Can anyone help? I think that the answer is actually quite simple, but I can't see the forest through the trees.
CementTruckAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
Hi, you can work with this:

<select onchange="launch(this.options[this.selectedIndex].value);">
  <option value="" selected="selected">Select one</option>
  <option value="1.pdf">PDF</option>
  <option value="1.cfm">CFM</option>
</select>

<script type="text/javascript">
  function launch(url) {
   if(url.match(/\.pdf$/i) {
      window.open(url, 'pdfpopup');
   } else {
      window.location = url;
   }
  }
</script>

-r-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CementTruckAuthor Commented:
<select onchange="launch(this.options[this.selectedIndex].value);">
  <option value="" selected="selected">Select one</option>
  <option value="1.pdf">PDF</option>
  <option value="2.pdf">PDF</option>
  <option value="3.pdf">PDF</option>
  <option value="1.cfm">CFM</option>
  <option value="4.pdf">PDF</option>
  <option value="2.cfm">CFM</option>
</select>

So, looking at the javascript portion you sent me, the option values I have above should work, right?

Let me try it. Thanks.
0
CementTruckAuthor Commented:
Hmmm. I get an "error on page". I've tried removing the ' value="" selected="selected" ', thinking that might be it, but I can't seem to get it to work. I even just copied and pasted what you sent, making sure the script was within the head tags, and made a link outside the options tag, copied the known good link and pasted it in the value (value=" pasted known good link here ") of one of the options. Still no worky. Any thoughts?
0
CementTruckAuthor Commented:
Never mind. Found it :)

  if(url.match(/\.pdf$/i) {                needed to be
  if(url.match(/\.pdf$/i)) {

Missing a closing parenthesis.

Works great!

Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.