0

ISSUE SOLVED. Chance type="submit" to type="image" within input element HTML.

On my home page I have an image of a heart. It is interactive and can be clicked. Over the couple of days I have made a lot of changes to the html/css/js.. all logged well in github.

Since this morning the heart image is not shown on the home page as a default anymore, but rather an input element is shown. When I click on it, than it shows the heart image again and it continues to works as normal.

Can it be due to a chronological issue with javascript? or am I overlooking something? I've been looking at my code since morning. I am certain as always it must be something stupid..

Right now my internet is insanely bad, so I can't upload any images. But a hand pointing into the right direction would be great.

https://jsfiddle.net/yzac8we8/

I have the image shown in html like this:

<div id="tapDiv"><input type="submit"  id="search" src="img/heart.png" value=""><div>

and the JS looks like this:

//Start Heart Beat Calculation
var lastTapSeconds = 0;
                        var bpm = 0;

                        //extra variabelen voor functionaliteit uitbreiding.
                        var beats = [];
                        var average = 0;
                        var count = 0;

                        var tapDiv = document.getElementById("tapDiv");

                        $(tapDiv).on('click', function() {
                        var tapSeconds = new Date().getTime();

                        bpm = ((1 / ((tapSeconds - lastTapSeconds) / 1000)) * 60);
                        lastTapSeconds = tapSeconds;
                        tapDiv.innerHTML = '<h1 style="display:inline;">' + Math.floor(bpm) + '</h1><img style="height:256px;width:256px;" src="img/heart.png"/>';

                        //extra functionaliteit
                        beats.push(Math.floor(bpm));
                        average *= count;  //average = average * count
                        average += Math.floor(bpm);  //average = average + count
                        count++;
                        average /= count;  //average = average / counterIncrement

                        //als array entries 10 heeft bereikt geef prompt met gemiddelde bpm.
                        if(beats.length >= 10) {
                        //alert("Your Average Beats Per Minute: " + average);

                            if ( average > 60 && average < 100 )
                            alert( "You have a normal resting heart rate. Good Job!" );
                            else if ( average < 60 )
                            alert( "You have an efficient heart function and better cardiovascular fitness. Keep it up!" );
                            else if ( average > 100 )
                            alert( "Your resting heart has an high average, indicating an unefficient and most likely unhealthy heart." );
                            else
                            alert( "Please measure again, your measurements seem unregular..." );

                            if(beats.length >=10){

                               beats.length = 0;
                               bpm = 0; 
                           }                        
                          }
                        });

Please do understand that I have this encapsulated within a bunch of other code that makes for the character of the web app. So a lot more dimensions can be of influence to this problem.

So what the problem actually is: On my homepage it should show the image of the heart within the division element. Like it always did. And I can click the heart because it's interactive. However, currently it only shows and input element and not the heart. But I only need to click the input element and it goes back to the old (normal) design of the heart image. It goes back every time I press refresh-page or start going to the webpage for the first time.

ISSUE SOLVED. Chance type="submit" to type="image" within input element HTML.

This question is unique in context to it's presumed duplicate, in that the input element with type="submit" has worked, albeit the fact that it shouldn't have. It might be due to the fact that the jQuery chronology within the code that also uses inner HTML for the image used within the input element (which is encapsulated by a division). It has been influenced so, that it has managed to be under the radar for these couple of weeks.

MSD
  • 311
  • 2
  • 3
  • 20
  • 1
    Create a similar demo [here](http://www.jsfiddle.net) – divy3993 Oct 10 '15 at 16:31
  • 1
    I believe in order for an input element to be treated as an image it has to have type as image not submit so `type="image"` – Patrick Evans Oct 10 '15 at 16:42
  • @PatrickEvans the strange this is, I have had it set to "submit" since the beginning and it worked just fine. – MSD Oct 10 '15 at 16:44
  • @PatrickEvans It worked! I changed it to "image" and it worked. You solved my problem. It is very logical, but the problem was, that it worked since the beginnen. I don't know why it suddenly mattered to be "image" instead of "submit". Thank you for your help. – MSD Oct 10 '15 at 16:47
  • Instead of updating the question, post an answer if you have solved the problem. You can post answers to your own question. – Anders Oct 10 '15 at 17:02
  • @Anders That's a good option, I will, thank you. – MSD Oct 10 '15 at 17:03

1 Answers1

0

Altered:

<div id="tapDiv"><input type="submit"  id="search" src="img/heart.png" value=""><div>

to:

<div id="tapDiv"><input type="image"  id="search" src="img/heart.png" value=""><div>

The strange thing about this is that the logical is apparent. However, it most likely went by me because of the fact that it has been working with type="submit" for weeks now. These couple of days I have made at least 23 commits to the web app and therefore somehow some influences have made it so, that it "errored" the default correction.

MSD
  • 311
  • 2
  • 3
  • 20