I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p>
4.2 Output: The first 20 Fibonacci numbers, which are defined as in
the sequence
1, 1, 2, 3, . . .
</p>
<p>
4.3 Input: Three numbers, using prompt to get each.
Output: The largest of the three input numbers.
Hint: Use the predefined function Math.max.
</p>
<form>
<p>
<label> <input type="radio" name="exerciseButton"
value="exercise1" href="#" onclick="switchCSS('exercise1.js',
0);">4.2 </label>
<label> <input type="radio" name="exerciseButton"
value="exercise2" onclick="" />4.3</label>
</p>
</form>
<script>
function switchCSS(files, links) {
var oldL = document.getElementsByTagName("link").item(links);
var newL = document.createElement("link");
newL.setAttribute("rel", "stylesheet");
newL.setAttribute("type", "text/css");
newL.setAttribute("href", files);
document.getElementsByTagName("head").item(0).replaceChild(newL,
oldL);
}
</script>
</body>
</html>
Exercise1.js
// 4.2
var output = "0 1";
var n = 19,
f = 0,
s = 1,
sum = 0;
for (var i = 2; i <= n; i++) {
sum = f + s;
output += ' ' + sum;
f = s;
s = sum;
}
}
window.alert(output);
Exercise2.js
//4.3
function maxNum(num1, num2, num3) {
var max = 0;
if ((num1 >= num2) && (num1 >= num3)) {
max = num1;
} else if ((num2 >= num1) && (num2 >= num3)) {
max = num2;
} else {
max = num3;
}
return max;
}
var arr = [];
for (i = 0; i < 3; i++) {
arr[i] = parseInt(prompt("Enter a number"));
}
document.write(maxNum.apply(this, arr));
I have edited your code as per your requirement hope it satisfies your conditions:-
html code :-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="exercise1.js"></script>
<script src="exercise2.js"></script>
</head>
<body>
<p>
4.2 Output: The first 20 Fibonacci numbers, which are defined as in the sequence
1, 1, 2, 3, . . .
</p>
<p>
4.3 Input: Three numbers, using prompt to get each.
Output: The largest of the three input numbers.
Hint: Use the predefined function Math.max.
</p>
<form>
<p>
<label> <input type="radio" name="exerciseButton" value="exercise1" href="#" onclick="Test1()">4.2 </label>
<label> <input type="radio" name="exerciseButton" value="exercise2" onclick="maxNum()" />4.3</label>
</p>
</form>
</body>
</html>

exercise1.js code:-
function Test1() {
var output = "0 1";
var n = 19,
f = 0,
s = 1,
sum = 0;
for (var i = 2; i <= n; i++) {
sum = f + s;
output += ' ' + sum;
f = s;
s = sum;
}
window.alert(output);
}

exercise2.js
function maxNum() {
var arr = [];
for (i = 0; i < 3; i++) {
arr[i] = parseInt(prompt("Enter a "+ (i+1)+ " number"));
}
var num1=arr[0]
var num2=arr[1]
var num3=arr[2]
var max = 0;
if ((num1 >= num2) && (num1 >= num3)) {
max = num1;
} else if ((num2 >= num1) && (num2 >= num3)) {
max = num2;
} else {
max = num3;
}
alert("*** MAx number is *** \n\t\t"+max);
}

Output:-

*******************************************************

4.3 output:-




I am trying to make it so that radio buttons when clicked execute a javascript file....
I am trying to create a slide show using JavaScript. This is what I have so far: HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Slide Show</title> <link rel="stylesheet" href="main.css"> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="slide_show.js"></script> </head> <body> <section> <h1>Fishing Slide Show</h1> <ul id="image_list"> <li><a href="images/casting1.jpg" title="Casting on the Upper Kings"></a></li> <li><a href="images/casting2.jpg" title="Casting on the Lower Kings"></a></li> <li><a href="images/catchrelease.jpg" title="Catch and Release on the Big Horn"></a></li> <li><a href="images/fish.jpg" title="Catching on the South Fork"></a></li> <li><a href="images/lures.jpg" title="The Lures for Catching"></a></li> </ul>...
Javascript on implementing dynamic calculation using a form. How do I get the text in the yellow box to display "You can play FGO!" when all yeses are checked, or "You cannot play FGO!" otherwise? <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Form</title> <link rel="stylesheet" href="css\survey.css"> <script src="js\survey.js"></script> </head> <body> <form id="part1"> <fieldset> <legend>Can you play FGO?</legend> <p>Do you have a smartphone?: ...
How can I connect the html forms to php --> mysql database <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h2> <center> Average: </h2> <h3> <center> Rate the following: </h2> <h3> <center> Rating Criteria: <br> Developing (0-5), Competent (6-10), Accomplished (10-15); </h3> <center> Judge Name: <input type="text" id="judge"> <br> <br> <center> 1. Articulate requirements and design of the project: <input type="text" id="num1"> <br> <br> 2. Plan the solution and implement the project: <input type="text" id="num2"> <br> <br> 3....
Using Javascript, I have two radio buttons, depending on the value of the radio button 1 or 2, you will send a different form to the user. So, if radio button is value "1" send new form1 or if value "2" send new form 2. New form will ask for letter grades for four courses in textboxes. Onsubmit of new form letter grades A,B,C,D need to be changed to numeric values 1,2,3,4 so an average grade for the four couses can...
How do i make my html show 10 results per page, and how do i make the books clickable to show results about them? <!DOCTYPE html> <html> <head> <title>Google Books Search</title> <script src="https://code.jquery.com/jquery-2.1.4.min.js"> </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> <style> body{ background:lightblue } .wrap{ max-width:400px; margin:auto; margin-top:10px; } .pagination, pagination-last{ float:left; } a{ text-decoration:none; padding:15px 20px; border:1px solid black; border-right:none; background:#f2f2f2; font-size:18px; font-weight:bold; } .pagination-last a{ border-right:1px solid black; } a:hover { background:orange; color;white; } </style> <!-- <script src="js/main.js"></script> --> <script> function B_Search()...
I am working on a normal javascript program where i have to take two names and put them in array and print out in sorted order.But,when the user clicks the print button it should show the output,but if user clicks second time,it should start again(basically reload the page).I have done the part about userinput and sorting and printing,but couldn't get the function of when user clicks button second time. <!DOCTYPE html> <html> <body> <input type="text" id="Name1" value=""><br> <input type="text" id="Name2"...
can you do this js and html question. ill give you the html and
js and css files just fix my error use if and else like what i did
dont use switch just fix my erorr.
<!DOCTYPE html>
<!-- Webpage HTML document for Lab 4.
Authors: Amirhossein Chinaei, Andriy Pavlovych
For: EECS 1012, York University, Lassonde School of Engineering
-->
<html lang="En">
<head>
<meta charset="UTF-8">
<!-- title for web page -->
<title> EECS1012: Lab 4 - Computational Thinking
</title>...
Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...
i need the code that goes within the <script> opening
and closing following the insturctions of the insturctions of the
pasted assignment screen shots please.
<!DOCTYPE html>
<html>
<head>
<!--
JavaScript 6th Edition
Chapter 3
Hands-on Project 3-1
Filename: index.htm
-->
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width,initial-scale=1.0">
<title>Hands-on Project 3-1</title>
<link rel="stylesheet" href="styles.css" />
<script
src="modernizr.custom.05819.js"></script>
</head>
<body>
<header>
<h1>
Hands-on Project 3-1
</h1>
</header>
<article>
<h2>Lunch selections</h2>
<form>
<input type="checkbox" id="item1" value="8" />
<label for="item1">Fried chicken
($8.00)</label>
<input type="checkbox"...