Login
Remember
IF Answers
Ask a Question

# Why does this Javascript not work in squiffy but will in a js editor

0 votes
191 views
asked May 19 in Authoring by Rockenden

Hi,

Why does the button execute in a js editor but not in squiffy?

Many thanks,

- squiffy

## 1 Answer

+1 vote
answered May 24 by Alex (486 points)

It seems the script tag is messing up parsing the Squiffy file for some reason.

But you don't need to use script tags - you can run JavaScript by indenting it at the top of a passage or section.

For example, here's how you display your button and bind some JavaScript to it:

        $(document).on("click", "#enter-name", function () {
            alert('ok...');
        });

    <button id="enter-name">Enter name</button>

To see this working, go here: http://docs.textadventures.co.uk/squiffy/scratchpad/?gistid=0b04d3378e7f93341e39&filename=gistfile1.txt

## Related questions

- Can I add dud links and tooltips in Squiffy with Javascript?
- How to add a random number generator in Squiffy?
- Random text in Squiffy
- How to compare two variables in Squiffy?
- How to deal with large numbers in Squiffy?

...