Jump to content

Need help with: Unexpected identifier & is not defined


vmars316

Recommended Posts

Hello & Thanks: 

"Uncaught SyntaxError: Unexpected identifier" for :

if imageCount = 1 {  nextImage = "background-image-02.jpg" ; elem.src = nextImage ;}

 
? I tried  various combinations   including "elem.src.value" but no go ?
Need help .

And "Uncaught ReferenceError: changeImage is not defined
 at HTMLInputElement.onclick " for :

<input type="button" onclick="changeImage()" value="Change Image">

 
I don't get how " changeImage is not defined  " ?
Need help . 

Thanks

Link to comment
Share on other sites

Thanks ,

Yes there is :

  function changeImage() {

That's what confounds me :( 

Sorry I forgot to post code:

<!DOCTYPE html>
<html>
	<head>
		<title></title>
	</head>
<body>
	<h5>Changing Image</h5>

<img src="background-image-01.jpg" id="myImage" />

<br>
    <input type="button" onclick="changeImage()" value="Change Image">

<script language="javascript">
    var imageCount = 0 ; var nextImage = "" ;
  function changeImage() {
    imageCount = imageCount + 1 ;
    elem = document.getElementById("myImage"); 
    if imageCount = 1 {  nextImage = "background-image-02.jpg" ; elem.src = nextImage ;} 
    if imageCount = 2 {  nextImage = "background-image-03.jpg" ; elem.src = nextImage ;} 
    if imageCount = 3 {  nextImage = "background-image-04.jpg" ; elem.src = nextImage ;} 
    if imageCount = 4 {  nextImage = "background-image-01.jpg" ; elem.src = nextImage ;} 
	if imageCount = 4  { imageCount = 0;}
  }
</script>

<!--
    <script>
		    var imageCount = 0 ;
        function changeImage() {
            var image = document.getElementById('myImage');
		    imageCount = imageCount + 1 ;
		    if imageCount = 1 {image.src("background-image-02.jpg")} 
		    if imageCount = 2 {image.src("background-image-03.jpg")} 
		    if imageCount = 3 {image.src("background-image-04.jpg")} 
		    if imageCount = 4 {image.src("background-image-01.jpg")} 
			if imgCount = 4 { imageCount = 0}
        }
    </script>
-->
<p><strong>Note:</strong> Click on the "Change Image" button to changeImage</p>
</body>
</html>

Oops , turns out I forgot the () around  " if imageCount = 1 { }"   

should be if (imageCount = 1) {  nextImage = "background-image-02.jpg" ; elem.src = nextImage ;} 

Edited by vmars316
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...