Tuesday 22 November 2011

Loading and Passing Images and Text values to JavaScript Function Dynamically

<html>
<head>
<script type="text/javascript">
function loadDoc(disimg)
{
alert(disimg);
document.write(disimg);
document.write("<p>"+disimg+"</p>");
document.getElementById("myDiv").innerHTML="<p>"+disimg+"</p>";
document.getElementById("myDiv").innerHTML="<img src="+disimg+".jpg"+"/>";
}

function loadDoc2(disimg)
{
alert(disimg);
document.getElementById("myDiv").innerHTML="<img src="+disimg+".jpg"+"/>";
}

</script>
</head>
<body>
<div id="myDiv" style=" width:400px; height:400px;"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadDoc('cat')">Change Content</button>
<button type="button" onclick="loadDoc2('cat')">ChangeImage</button>
</body>
</html>

No comments:

Post a Comment