/    Sign up×
Community /Pin to ProfileBookmark

Buttons and javascript

Can someone please help me make a button which prints thank you when clicked? I know there are lots of ways to do this but in my circumstance I need to use an if statement and this has me totally stumped. I have not done much because I am totally unsure on what syntax to use. I have made a website for a school project and it has a form on one of the pages. It is requirement to use javascript to do something with an if statement. I would like to have a button at the bottom of the form which does something to the page when clicked. I don’t really mind what happens but I thought a thank you message would be nice.

Cheers 🙂

<!DOCTYPE html>
<html>

<body>
<button id=”sub”>Subscribe</button>
</body>

<script>
function button () {
var message = document.getElementById(“message”);

if (sub.onclicked == true) {
/*Pop up with thank you*/
};
};

button ();
</script>

</html>

to post a comment
HTMLJavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@codyhillSep 15.2019 — @MatthewGeorgetti#1608753 Hi there!

So, using an if statement for that is kinda the wrong way doing it. Doing that with the if statement you are just complicating yourself.

I have codded what you want here: https://codepen.io/raul-rogojan/pen/wvwxqKM?editors=1010

I give you 3 examples.

Example 1 - how I would normally code that

Example 2 - the same thing but using an if statement

Example 3 - I did not know what you are referring to by "print" so I made a pop-up. This is a bit difficult to do but you have it there. I also tried to make it with if statement but I fail and I did not allocate too much time for this.

I think Example 2 is what you need for your project. Hope this helps!

Also If you want me to example the code I will.
Copy linkTweet thisAlerts:
@MatthewGeorgettiauthorSep 15.2019 — Thank you so much! This is exactly what I was looking for.
Copy linkTweet thisAlerts:
@codyhillSep 15.2019 — @MatthewGeorgetti#1608755 np
×

Success!

Help @MatthewGeorgetti spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...