Hello again! I have moved to JavaScript and am having problems with an example. I have decided to try handling it bit by bit. The first issue I am dealing with, though, appears to be an HTML issue rather than a JavaScript issue.
Specifically, I have a question, “Are you the President?”, with two radio buttons labeled “Yes” and “No”. If the user checks Yes, the browser should display the phrase “Mr. President”. If the user checks No, the browser should display “Sir”. I can get the Sir when I click yes, but I can’t get the “Mr. President” when I click no. If I eliminate the Mr. and just have President, it works. The problem is that several examples in my book of both document.write quotes and alert quotes allow phrases that include punctuation and spaces. So why is it not working in this example?
Here is the code. I have run it as both a document.write and an alert. FYI, the next step is to try to assign a value to a variable when I click a choice rather than do a doc write or an alert. I would then use the variable in my script.
<html>
<body>
<form>
<p>Are you the President?<br />
<input type=“radio” name=“pres” value=“no” onclick=alert(“Sir”) />No<br />
<input type=“radio” name=“pres” value=“yes” onclick=alert(“Mr President”) />Yes</p>
</form>
</body>
</html>
Thanks!