Sophiesu
Sophiesu

Reputation: 3

Getting alert to pop up

This is the HTML Code

<p>
 filename:
<input type="text" id="finput">
<input type="button" value="upload" onclick:"uploadText()">
</p>

This is the javascript function I tried to write and call:

function uploadText(){
  var textinput= document.getElementById("finput");
  var userinput= textinput.value;
  alert ("you chose" + userinput);
  };

I'm not sure whats wrong. When I click the button, there is no response or alert. I am using codepen do write this code. Any insight into what I'm doing wrong?

here is a link to the codepen : https://codepen.io/sophiesucode/pen/qBEoOEV

Upvotes: 0

Views: 39

Answers (1)

Maxx
Maxx

Reputation: 134

In html, you assign with an equal sign (=) and here you have a colon (:) in the assignment of the event handler.

Colons are used in CSS styles but not HTML. Change it to an equal sign and it works.

<input type="button" value="upload" onclick="uploadText()">

Upvotes: 1

Related Questions