Jump to content
vmars316

Need help with: Unexpected identifier & is not defined

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...