Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript JavaScript Presentation issue

Hi. I'm a 78-year-old retired mainframe systems programmer trying to learn some new tricks. I've re-written an old C++ program of mine that translates Swahili to English in JavaScript and paired it with HTML and it works but the presentation is sloppy. I'm trying to learn a new presentation tool but it's not working.
<p id="dataout"></p>
let node = document.createTextNode("noun count = " + noun_count );
document.getElementById("dataout").appendChild(node);
Not only is this not writing to the screen, it seems to be stopping the entire program dead at that point.
Any suggestions will be most appreciated.
 
Can we see the whole code?
Hi. If you mean the whole JavaScript program, including the vocabulary, it is over 23,000 lines.
What precedes the code I included and is relevant is just:
let noun_count = nounload();
which returns the count of entries in the noun dictionary.
The entire HTML is as follows
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Swahili to English translation program</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="presentation.js"></script>
</head>
<body>
<h1>SWAHILI - Kiswahili to English translation program.</h1>
<p>
Version 1.0 as of 06/11/2024<br>
COPYRIGHT (C) 2024 MORRIS DAVID FRIED<br>
It come with ABSOLUTELY NO WARRANTY; for details type 'qw'.<br>
This is free software and you are welcome to redistribute it under certain conditions;<br>
type 'qc' for details.
</p>
<button id="swahili_word">Please enter a Swahili word to be translated to English.</button>
<p id="dataout"></p>
</body>
</html>
 
Maybe this will help clarify my issue. I had a version of my program that used document.write to write this data to the screen. It worked but I didn't like where it showed up on the screen and I wanted more control over that. That's when I tried using the appendChild technique and I would like to see how that comes out but I can't seem to get it to work.
 
I'm not experienced in javascript but, I got this to work from examples on w3school. If this is something like your wanting

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        function myfunc() {
            const node = document.createElement('p');
            const textnode = document.createTextNode('Hello World');
            node.appendChild(textnode);
            document.getElementById('dataout').appendChild(node);
        }
    </script>
</head>
<body>
    <button id="swahili_word" onclick="myfunc()">My Button</button>
    <p id="dataout"></p>
</body>
</html>
 
Thank you much. I still have a lot of work to do but I have made some progress with your help. My problem was not what I coded but where I placed it in my program. I placed it before the function that responded to the button. When I moved it into that function, it worked. I guess the lesson that I needed to learn is that, before the button is pressed, these statements can't be used. Peace out.
 

New Threads

Buy us a coffee!

Back
Top Bottom