...

View Full Version : Javascript alert problem



many_tentacles
09-05-2008, 03:17 PM
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??


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

rnd me
09-07-2008, 09:03 AM
in the line:

<select name="menu1" onchange="PopUp('caption',value)">

change:

onchange="PopUp('caption',value)"

into:


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.

many_tentacles
09-08-2008, 11:03 AM
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?


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum