I am showing/hiding divs with jQuery. The following code works on a normal page, but does not work in my page that is loaded with AJAX in a new <div>
:
<script>
$(document).ready(function (){
$("#pic_video").change(function() {
// foo is the id of the other select box
if ($(this).val() == 1) {
$("#pic_amount_id").show();
$("#vid_duration_id").hide();
}
else if ($(this).val() == 2) {
$("#pic_amount_id").hide();
$("#vid_duration_id").show();
}
else if ($(this).val() == 3) {
$("#pic_amount_id").show();
$("#vid_duration_id").show();
}
});
});
</script
<p style="margin-top:15px;"><b>Select</b></p>
<span class="small"></span>
<select name="pic_video" id="pic_video" style="width:95%;margin-top:6px;">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
<div id="pic_amount_id">TEST</div>
<div id="vid_duration_id">TEST2</div>
The above is placed in my page that is loaded with Ajax. The ajax script (JavaScript) is a bit long to add here, but maybe the jQuery has to be loaded during/after the ajax?
The ajax is triggered with normal JavaScript during a onclick=''
event and loaded into a new <div id='result'>
<a href onclick="loadAjax2(...)"...>Click here</a>.
And the loadAjax2()
script triggers the usual ajax javascript:
function loadAjax(...) {
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
...
xmlhttp.open("GET",strURL+'&'+Math.random(),true);
xmlhttp.send();
}
What am I forgetting? Or is mixing jQuery/JavaScript not a good idea here?