Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    34
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Popup Message When Specific Option Selected

    Hi,

    I have a dropdown box with a few options that can be selected. Is it possible to have a popup message when just a specific option is selected?

    I.e. in the select list below, people can select low or medium without getting a warning, but if they select High, a popup warning appears?
    <script>
    function popup () {
    alert(\'Only select high prority if this is currently stopping you from working\');
    }
    </script>

    <select name="level">
    <option value="low">Low</option>
    <option value="medium">Medium</option>
    <option value="high" onClick="popup()">High</option>
    </select>

    Many thanks

    Ben

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    This one is erroneous:
    Code:
    alert(\'Only select high prority if this is currently stopping you from working\');
    You should remove highlighted.

    If your intention is to alert the message with quotes on it, then you should add highlighted:
    Code:
    alert('\'Only select high prority if this is currently stopping you from working\'');
    Alternatively, you might find another way to skin a cat:
    Code:
    <script type="text/javascript">
    function popup (el)
    {
    if(el.value.toLowerCase()=='high')
    	alert('\'Only select high prority if this is currently stopping you from working\'');
    }
    </script>
    
    <select name="level" onchange="popup(this)">
    <option value="low">Low</option>
    <option value="medium">Medium</option>
    <option value="high">High</option>
    </select>
    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    bjblackmore (12-08-2008)

  • #3
    New Coder
    Join Date
    Dec 2008
    Posts
    34
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hi rangana,

    Thanks for the reply.

    That seems to have done the trick.

    Ref the backslashes, that was a posting error. I'm programming Java/HTML inside a PHP page, and needed to use the backslash to cancel out the single quote in the javascript. I forgot to remove it when I copy & pasted the code.

    Thanks again

    Ben


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •