(index):61 Uncaught ReferenceError: fnspeak1 is not defined - javascript

I have created a text to speech programm..and i get a error message which is give below
This is my program..
Html
<textarea id="message"></textarea>
<button type="button" onclick="fnspeak1()">
Play
</button>
Js
function fnspeak1()
{
var msg = new SpeechSynthesisUtterance(document.getElementById("message").value);
window.speechSynthesis.speak(msg);
}
However when run..and when the play button is clicked:
I get a error message like this:
Uncaught ReferenceError: fnspeak1 is not defined
Can someone help me with this..Thanks in advance
Ps;i am a beginner in js

I think you should type more code for me to analyze.
add window.onload = fnspeak1(){ your js code }or Jquery $(document).ready( your funciton here )
is your function under other action? for example: $(".a").on('click',function(){ your function })
if your html and js not in one page ,have you included js in the right way?

Related

How to use function inside Javascript file using NodeJS

I start to develop a website using NodeJS and Express.
This website is about a Cinema and I have to develop a form which allows users to add a movie in database with informations like a list of actors.
I write a simple JS script to add an input to enter a new actor and I call this function addActor() in a script called dynamic.js. Here is my code :
console.log("Launching dynamic.js !")
function addActor(){
var txtNewInputBox = document.createElement('div');
txtNewInputBox.innerHTML = "<input type='text' id='newInputBox'>";
document.getElementById("actorsList").appendChild(txtNewInputBox);
}
Dynamic.js is stored in js repository so inside my app.js file I add the line :
app.use("/js", express.static("js"));
Of course I add this line in my file and I also add the button :
<script type="text/javascript" src="/js/dynamic.js"></script>
//.... some code ....//
<input type="button" name="addActor" value="ajouter" onclick="addActor()">
Here is the problem, when I click on the button, it returns "TypeError: addActor is not a function" but it prints "Launching dynamic.js !" so I don't know how to use my function addActor(). (If I called directly my function in web console it works so I don't understand)
If you have a solution, I will be glad to hear it ! Thanks ;)
Finally I find the problem. It's because I called my button "addActor" so it didn't distinguished my JS function and my HTML button.
<input type="button" name="addActor" value="ajouter" onclick="addActor()">
name="addActor" was the problem, now it works ! Thanks for helping ;)

new endeavor and my code isnt responding Renee

I am very new to web design and I am trying to get my javascript function and jquery to work. i have been trying to figure this out for a few days. with the function, I cant see why it wont work:
this is in my js file
function myFunction() {
document.getElementById("sign").innerHTML=
"Thank you for signing up!";,
document.getElementById("sign").innerHTML=
"I look forward to speaking with you soon";
}
this is in my html file
<button onclick="myFunction()">Sign Up</button>
<p id="sign"></p>
Here is the jQuery:
$("div:hidden:first").fadeIn(1000).delay(4000).slideUp(1000);
Have I written something wrong? Neither of these react.
I don't know exactly what's broken with your code,
wrapping the script tag in the bottom of your body should make all work well.
HTML:
<button onclick="myFunction()">Sign Up</button>
<div>
<p id="sign"></p>
</div>
JavaScript + jQuery:
var myFunction = function() {
let message = document.querySelector("#sign")
message.innerHTML = "Thank you for signing up!";
$("div:hidden").fadeIn(1000).delay(4000).slideUp(1000);
}
Is that what you wanted to achieve?
To make the message change, I think you have to use setTimeout so it changes/adds after few seconds...

Uncaught ReferenceError: <function> is not defined at HTMLButtonElement.onclick [duplicate]

This question already has answers here:
Why does this simple JSFiddle not work? [duplicate]
(8 answers)
Closed 5 years ago.
I have created my problem on JSFiddle at https://jsfiddle.net/kgw0x2ng/5/. The code is as follows
HTML CODE
<div class="loading">Loading…</div>
<button type="submit" onClick="hideButton()">Hide</button>
<button type="submit" onClick="showButton()">Show</button>
JS CODE
function hideButton(){
$(".loading").hide();
}
function showButton(){
$(".loading").show();
}
I am showing a spinner and I would like the spinner to hide when I click on the "Hide" button. I am getting the following error :
Uncaught ReferenceError: showButton is not defined
at HTMLButtonElement.onclick (VM282:180)
onclick # VM282:180
VM282:179
Uncaught ReferenceError: hideButton is not defined
at HTMLButtonElement.onclick (VM282:179)
onclick # VM282:179.
Can someone please suggest a solution?
Thanks
Sachin
Place your script inside the body tag
<body>
// Rest of html
<script>
function hideButton() {
$(".loading").hide();
}
function showButton() {
$(".loading").show();
}
</script>
< /body>
If you check this JSFIDDLE and click on javascript, you will see the load Type body is selected
Same Problem I had... I was writing all the script in a seperate file and was adding it through tag into the end of the HTML file after body tag.
After moving the the tag inside the body tag it works fine.
before :
</body>
<script>require('../script/viewLog.js')</script>
after :
<script>require('../script/viewLog.js')</script>
</body>

Api JS code does not seem to react to an onclick

I've been trying to get this JS code into one of my pages in Magento. Yet it does not let me run the code.
Javascript:
<script>
function emailSend()
{
rrApiOnReady.push(function() { rrApi.setEmail($("#newsletter").val(););});
}
</script>
#newsletter is the id of an <input type="text">
The button who needs to trigger the emailSendfunction:
<div class="actions">
<button type="submit" title="<?php echo $this->__('Subscribe') ?>" class="button" onclick="emailSend()"><span><span><?php echo $this->__('Subscribe') ?></span></span></button>
</div>
I've tried $(document).ready(function() {});
I've tried different methods to get this to work.
When using alert("Hello World"); it's working fine. Anything wrong with the api's given code?
Is there anything wrong with the code?
The Chrome console says this: Uncaught SyntaxError: missing ) after argument list
I've seen that it might be an extra }? Can't seem to find it...
Any tips or tricks to get this to work?
You could try something like this:
$(document).ready(function () {
$("#ButtonID").click(function (event) {
//stuff you want to do
});
});

alert message does not pop up

I have put the code on jsfiddle.net.
The problem I am having is that the function does not seem to get called when showToast button is clicked.
The actual code
<button type="button" onClick="showAndroidToast('Hello Android!')">Show Toast</button><br/>
function showAndroidToast(name){
alert("hi");
}
I got the error:
ReferenceError: Can't find variable: showAndroidToast;
Anyone help? Thanks!
The problem is that it is not onClick but onclick, and your function should be declared in some cases like this:
<script>
window.showAndroidToast = function(){
//code
};
</script>
<button type="button" onclick="window.showAndroidToast('Hello Android!')">
Show Toast
</button>
This is just to be found globally, just to be sure it is not a problem with the browser itself.
Remove type from your button tag:
<button onClick="showAndroidToast('Hello Android!')">Show Toast</button><br/>
//and check
Hope it helps

Categories

Resources