Remove the ;
after your function definition: function changeaudio(x);
should become:function changeaudio(x)
Also, your onclick
syntax is wrong: onclick='changeaudio(1)"'
should be: onclick="changeaudio(1)"
.
Your final code should look like this:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function changeaudio(x)
{
document.getElementById("audioplayer").src=x+".mp3";
document.getElementById("image").src=x+".png";
}
</script>
</head>
<body>
<center>
<img id="image" src="1.png" />
<audio id="audioplayer" src="1.mp3" controls autoplay loop>
Your browser does not support the audio element.
</audio>
<br />
<input type="button" id="play" value="Play 1" onclick="changeaudio(1)" />
<input type="button" id="play2" value="Play 2" onclick="changeaudio(2)" />
<input type="button" id="play3" value="Play 3" onclick="changeaudio(3)" />
</center>
</body>
</html>