Assignment 2 – Frequently Asked Questions

Question: I’ve written my Fiddle and absolutely nothing is happening, what could be my problem?

Answer: More than likely you have not set the Javascript Load Type. These are different options on how to load Javascript (or really how to execute the JavaScript on a page). This needs to be set one of the No Wrap options as shown.

Correct setting to execute Javascript for examples in COP3530

Question: How do I get variables entered by the user into the JavaScript code?

Answer: Users will be entering values into text boxes in the HTML, but you will probably want to use those values in the Javascript Code. Here is a simple example.

The HTML to place an input box for user entry

Note that the input textbox must have an id and you are going to use that id to retrieve the value entered by the user.

The Javascript function using the getElementById function to get the user entered value.

You should also note that the getElementById returns an element, NOT the contents of the element. To get the contents you must use the value property.

Question: How do I call the function once I wrote it?

Answer: If you want to call a function in response to a user action you must use the event triggered by the user to make the call. In this case it is easy, simply use the onclick event that is associated with a button that you can place in the html.

The addition of a button with a function call associated with the onclick event of a button.