I currently have some Javascript that looks a bit like this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
function changeSource(newSource) {
document.getElementById('preview').src = newSource;
}
});
</script>
Then I have some HTML that looks like this:
<table border=0 class="colors">
<tbody>
<tr>
<td><a onclick="changeSource('http://www.test.com')"><img width="40" src="test.png"/></a></td>
</tr>
</tbody>
</table>
Then the Iframe section:
<table border=0>
<tbody>
<tr>
<td><iframe id="preview" width="125" height="303" src="test.php" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" hspace="0" vspace="0"></iframe></td>
</tr>
</tbody>
</table>
However click on the image in the tags the Iframe’s source won’t change. Why is it like this?
You are getting an error because the function is a local method since you hid it in the onready function. There is no need for the onready call with that example.
needs to be
Better yet, no JavaScript is needed! Use HTML like it is supposed to be used. Use the target attribute.