[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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.
0
CementTruck
Asked:
CementTruck
  • 3
1 Solution
 
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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now