Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:40:15+00:00 2026-05-26T23:40:15+00:00

I am learning to code JavaScript. In this script, I want a link to

  • 0

I am learning to code JavaScript. In this script, I want a link to not go to its specified location, but to change the text in the paragraph before it. I have created a function to achieve it onclick, but the function is not able to return false.

<html>
<head>
    <title>Javascript Test #6</title>
    <script type="text/javascript">
        document.getElementById("links").onclick=writeData();
        function writeData()
            {
                document.getElementById("para").innerHTML="Changed Paragraph Content";
                return false;
            }
    </script>
</head>
<body>
    <p id="para">Unchanged Paragraph Content</p>
    <br/>
    <a id="links" href="javascript-return.html"> Click here to change the paragraph content </a>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:40:15+00:00Added an answer on May 26, 2026 at 11:40 pm
    document.getElementById("links").onclick=writeData;
    

    Don’t use the brackets. They force your function to evaluate. but you want to assign the function.

    EDIT:

    Of Course, you need to Assign your Function after the Document has been loaded. The way it is right now, there will be no element with id links when the assignment is executed. Basically, just put your script block below the links element.

    <html>
    <head>
        <title>Javascript Test #6</title>
    </head>
    <body>
        <p id="para">Unchanged Paragraph Content</p>
        <br/>
        <a id="links" href="javascript-return.html"> Click here to change the paragraph content </a>
    
        <script type="text/javascript">
            document.getElementById("links").onclick=writeData;
            function writeData()
            {
                document.getElementById("para").innerHTML="Changed Paragraph Content";
                return false;
            }
        </script>
    </body>
    </html>
    

    EDIT (Using window.onload):

    <html>
    <head>
        <title>Javascript Test #6</title>
        <script type="text/javascript">
            window.onload = function() {
                document.getElementById("links").onclick=writeData;
            }
    
            function writeData()
            {
                document.getElementById("para").innerHTML="Changed Paragraph Content";
                return false;
            }
        </script>
    </head>
    <body>
        <p id="para">Unchanged Paragraph Content</p>
        <br/>
        <a id="links" href="javascript-return.html"> Click here to change the paragraph content </a>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning jQuery and this is my code so far: <script type=text/javascript> $(document).ready(function(){ $('#login').click(function(){
I'm learning by reading this tutorial: Link Here's the code: <?php require_once 'Zend/Loader.php'; class
I'm looking through some code for learning purposes. I'm working through this portion of
I'm still learning ASP.NET and I often see code like this throughout parts of
This is a code snippet from O'Reilly Learning Opencv, cvNamedWindow(Example3, CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]);
I'm starting learning javascript for a project, I've found a script that does a
Why is the following code NOT working without id or name attribute specified for
I'm learning javascript and jquery and have written a very basic script inside my
<script type=text/javascript> $(#gallery).dragsort({ dragSelector: div, dragEnd: saveOrder, placeHolderTemplate: <li class='placeHolder'><div></div></li> }); function saveOrder() {
<html> <body> <script src=raphael.js type=text/javascript></script> <script>// Each of the following examples create a canvas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.