Hey guys,

I recently made a code that simply refreshes a page with new $_GET variables. This code worked perfectly in Firefox, but not Google Chrome or Safari. Here's just one piece of the code that I used, displaying the refresh.

<option value=PANC onclick=\"javascript:location.href='searchflight.php?dep=PANC'\">Anchorage, AK</option>

I also tried window.location.href, with no luck. Also, the \" is because this drop down is inside a PHP code.

Any help is appreciated 😃

    Although the W3C standards do state that <option> elements should support the 'onclick' event, I have never used nor seen it used before.

    Personally, I would use the 'onchange' event handler for the parent <select> element instead; you could then, for example, redirect to a location based on the new value selected in the dropdown (since it appears that is what you're attempting to do anyway).

    EDIT: Apparently it's an old/known bug in Webkit; see Chromium issues #31836 and #5284.

    Also consider this possible solution submitted on Stack Overflow.

      I tried using a function instead. Taking another example from stack overflow, I came along this function.

      function handleSelect(elm)
      {
      window.location = elm.value+".php";
      }

      That works, but when I try to change it around to how I need it, it doesn't do anything. It's most likely a formatting problem on my part.

      function insertdep(elm)
      {
      window.location = "/searchresults.php?dep="+elm.value+;
      }

        The '+' plus sign in Javascript is used for concatenation (much like the period for PHP strings), and the semicolon is used to terminate a statement.

        Your second version of the function attempts to concatenate elm.value with.... nothing, since you immediately follow the concatenation operator with a semicolon.

          Thanks, I got it working. The + at the end is what did it.

            Write a Reply...