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

Posted on 2006-04-20
Last Modified: 2012-05-05

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.
Question by:CementTruck
    LVL 49

    Accepted Solution

    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>

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


    Author Comment

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

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

    Let me try it. Thanks.

    Author Comment

    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?

    Author Comment

    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.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    I starting with php 11 71
    Required Field Notifications Not Aligned 4 33
    CSS WIld Cards 2 29
    Page not loading properly 15 24
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now