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
    Regular Coder
    Join Date
    Dec 2005
    Location
    UK
    Posts
    207
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Javascript alert problem

    Hi

    I have a bit of a problem which I can't for the life of me work out.

    I have a javascript which changes the content of a layer depending on which dropmenu item is selected.

    This is all good, but i then wanted to put another piece of javascript in the content that is revealed. There's a fairly obvious " and ' issue here though.

    Here's the basics of the code I'm trying to sort out. Any ideas would be much appreciated.

    Thanks

    I also can't get the javascript alert to work... any ideas on this one??

    Code:
    <script type="text/javascript">
    <!--
    function PopUp(mesid,txt){
     var messobj=document.getElementById(mesid);
     messobj.innerHTML=txt;
    }
    -->
    </script>
    
    <form name="form1" id="form1">
    	<select name="menu1" onchange="PopUp('caption',value)">
    		<option value="<h3>Select the next option from the list above</h3>">Select the next option</option>
    		<option onfocus="javascript:alert('ALERT HERE');" value="<p><a href='mylink.html' target='_blank' onclick='javascript:alert ("This is a Javascript Alert");'>Click here for a full itinerary</a></p>">Academy Week in Portugal</option>
    	</select>
    </form>			
    				
    <div id="caption">
    	<h3>Select the next option from the list above</h3>
    </div>
    Last edited by many_tentacles; 09-05-2008 at 04:02 PM.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    in the line:
    Code:
    <select name="menu1" onchange="PopUp('caption',value)">
    change:
    Code:
    onchange="PopUp('caption',value)"
    into:
    Code:
    onchange="PopUp('caption',this.options[this.selectedIndex].value)"
    option tags cannot receive focus. move the onfocus event to the select tag, and it should fire correctly.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Location
    UK
    Posts
    207
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Righty... That still didn't seem to work, so I'll concentrate on one thing at a time. My simple mind can't cope with too much.

    Basically, what I was trying to do is make my google analytics tracking work to record what is selected every time the drop menu is changed. Is this possible, or does my question even make sense?

    Code:
    <script type="text/javascript">
    <!--
    function PopUp(mesid,txt){
     var messobj=document.getElementById(mesid);
     messobj.innerHTML=txt;
    }
    -->
    </script>
    
    <form name="form1" id="form1">
    	<select name="menu1" onchange="PopUp('caption',value); pageTracker._trackPageview ('dropmenu/eithercatsordogs');">
    		<option value="<h3>Select the next option from the list above</h3>">Select the next option</option>
    		<option value="<p><a href='mylink.html'>cats here</a></p>">cats</option>
    		<option value="<p><a href='mylink.html'>dogs here</a></p>">dogs</option>
    	</select>
    </form>
    
    <div id="caption">
    	<h3>Select the next option from the list above</h3>
    </div>
    thanks for helping so far. please don't give up on me.


  •  

    Posting Permissions

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