Numerous Capabilities of Javascript

I have a question about JavaScript and how to implement multiple functions on a webpage. I am new to JavaScript and struggling with getting multiple functions to work successfully. I have searched online but can't find a solution that fits my specific needs. Here is an example of what I am attempting to achieve:

<html>
    <head>
        <script type="text/javascript">
            function frogger()
            {
                document.getElementById("descriptions").innerHTML="Frogger <br />Description: Get
                    the frog to the islands at the top of the screen without falling into the water or
                    getting hit by cars. <br />Controls: Up arrow key to move forward, down arrow key to
                    move backward, left arrow key to move left, and right arrow key to move right.";
            }
            function clear()
            {
                document.getElementById("descriptions").innerHTML=" ";
            }
        </script>
    </head>
    <body>
        <div id="descriptions" style="{height:100;}">
        </div>
        <div class="game" onmouseover="frogger()" onmouseout="clear()">
            <a href="/arcade/frogger.html"><img border="0" src="http://ggmedia.site50.net
/pics/frogger.PNG" height="100" width="100" /><br />Frogger</a>
        </div>
    </body>
</html>

If anyone has any advice or suggestions, I would greatly appreciate it!

Answer №1

It's recommended to choose a different name for your function as there is already a built-in function called clear in the document object.

Answer №2

Your text contains line breaks which can be removed or each line can be ended with a \ character.

function frogger()
{
    document.getElementById("descriptions").innerHTML="Frogger <br />Description: Get\
the frog to the islands at the top of the screen without falling into the water or\
getting hit by cars. <br />Controls: Up arrow key to move forward, down arrow key to\
move backward, left arrow key to move left, and right arrow key to move right.";
}

​ Edit: Changing the name of the clear function to clearx seems to make it work, which is odd.

Edit: It seems there is a clear method in the document object

Answer №3

function leadCharacter() {
    document.getElementById("details").innerHTML="Help the main character navigate through obstacles and reach the goal without losing lives or getting caught by enemies. Use the arrow keys to move around - up to move forward, down to move backward, left to move left, and right to move right.";
}

Answer №4

Modify the clear() method to a different name. I decided to rename it as clearDesc() and it functioned correctly (once I resolved the string line break problem). Check out the solution here.

Answer №5

  <div class="game" onmouseover="frogger()" onmouseout="clearr()">mousee</div>
    <div id="descriptions"></div>
    <script type="text/javascript">
        var frogger = function () {
            this.innerHTML = ["Frogger <br />Description: Help the frog reach the islands at the top of the screen without falling into the water or",
                    "getting hit by cars. <br />Controls: Use the arrow keys to navigate - up to move forward, down to move backward, left to move left, and right to move right."].join('');
        }.bind(document.getElementById("descriptions"));
        //
        var clearr = function () {
            this.innerHTML = " ";
        }.bind(document.getElementById("descriptions"));

    </script>

Check out this code on jsfiddle.net

http://jsfiddle.net/uniquecode/89Jkt/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Check if jQuery condition is met for classes that match exactly

The PHP echo statement below contains the code. The brackets are empty, but I can guarantee that the statement inside, which modifies CSS, works - except for one issue. I want it to only target elements with a class attribute equal to "zoom" or "zoom firs ...

Encountered a JavaScript error while using Internet Explorer

My web and Jquery plugins are working flawlessly on various browsers such as Firefox, Chrome, Safari (Windows & OSX), and Android. However, they encounter issues with Windows and Internet Explorer as some JavaScript fails to load. It's frustrating tha ...

React Module cannot be found: Error: Unable to locate - import paths

New to coding and currently working on a website using React. Encountering three errors persistently: ERROR in ./src/Components/Pages1/Home.js 6:0-50 Module not found: Error: Can't resolve './Components/Cards/Cards1.js' in 'C:\Use ...

Attempting to reset the altered values proves ineffective in different Ctrl instances within AngularJS

I'm feeling a bit disoriented regarding my current issue. The scenario involves two views and a controller that interact with a service. The first view consists of a table list containing items loaded from a WebAPI. The service sends requests to the s ...

Attempting to reset my react-final-form fields led to receiving an empty object as the values instead

Currently, I am facing a situation where I need to clear all field values except for "retainThisObj" upon the initial page load. The problem I encountered is that my { } ended up empty, meaning that my "retainThisObj" was also deleted. ...

Developing a Secondary User within Meteor.JS after Establishing the Primary User

Is it possible to automatically create a secondary user upon registration of the primary user using a form generated with the useraccounts:core package? An issue arises when attempting to run Accounts.createUser within Accounts.onCreateUser, resulting in ...

Creating a p5.js circle on top of an HTML image: A step-by-step guide

Currently, I am integrating an image into my web application using standard JavaScript and HTML. The image represents a basic map, and my objective is to utilize p5.js to draw on it. <div id="map"> <img src="Assets/MENA.jpg" ...

Guide to activating form elements using a JQuery function

I need help setting up a form with 11 rows and 11 columns. By default, the form fields should be disabled, but when I click on an "EDIT" button, they should become enabled. Any assistance would be greatly appreciated. Thank you in advance. Here is my edit ...

Issue with Google Tag Manager click event not propagating to parent element

I am currently configuring Google Tag Manager for a client's website and encountering difficulties in getting click event tags to activate. Although I have set the trigger to activate based on the button's CSS selector, the actual button contain ...

Issue with slideout menu hyperlinks malfunctioning

Currently developing a site at , everything seemed ready for deployment until testing in 320x480 mode on mobile revealed that the links on the slideout menu were not working on any mobile device I tried, regardless of resolution or page. I've tried u ...

What is the safest method for integrating a private MD5 key into a JavaScript algorithm?

Looking to incorporate online payments into my website using html and jquery. The simplest method seems to be sending a form to a specific link. One of the parameters required is a signature, which is a hash generated from form fields and a private key. Ho ...

Tips on restricting users to choose dates that are later than the current date

Currently, I am working with Vue3 using the options API. After reviewing this StackBlitz, my question is regarding how to correctly set the :max value for a date-picker. Even though I have assigned :max as new Date(), I am still able to select dates that ...

The Vue.js component experiencing issues with the Foundation 6 modal functionality

I'm facing an issue with my vue.js single file component. I have a button that is supposed to open a modal with a video from zurb foundation. However, every time I click the button, the page reloads without showing any errors in the console or network ...

Accessing Session Objects in Struts2 Using a Different Session Object as a Key

I am fairly new to working with Struts2 and currently, I am faced with the challenge of retrieving a session object using a dynamic session key. Here's how my application flow goes: The user will trigger the action from their browser http://localhos ...

React Prop Local Modal Redux

Just diving into the world of React and Redux, and I'm a bit lost on how to effectively utilize both local properties and redux properties simultaneously. After trying different approaches without success, I'm reaching out for guidance. My goal i ...

The Faux-Dynamic News Feed on a stationary website

As I work on revamping my employer's static website, it has become clear that a news section needs to be integrated. The site is being built using the Bootstrap 3.0 framework. My plan is to implement the following strategy: I aim to have a JavaScrip ...

"Troubleshooting ways to resolve babel-eslint import/export issues without the need for a configuration

Upon running npm start, I encountered the following error message: Parsing error: 'import' and 'export' may only appear at the top level After investigating this issue, suggestions included updating the eslint configuration file with ...

Retrieve information from the database and showcase it in a competitive ranking system

Here is the HTML and CSS code for a leaderboard: /* CSS code for the leaderboard */ To display the top 5 in the leaderboard, PHP can be used to fetch data from the database: <?php // PHP code to retrieve data from the database ?> The current ou ...

Having difficulty loading the controller into my AngularJS module

I've been attempting to organize my angularjs controllers into separate files without success. Folder Structure: --public-- --js/controller/resturant.js --js/master.js --index.php Content of master.js angular.module("rsw",[ ...

Any recommendations for updating input in a directive without relying on $broadcast?

I am currently facing an issue with my contact list on controller A. Whenever I select a contact, the contact's information gets broadcasted to controller B and also to the datepicker directive in controller B. Although this method works, I am wonderi ...