I am attempting to disable a button using an external JavaScript - activated by a submit button
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Join Email List</title>
<link rel="stylesheet" target='_blank' href="Radio_Button.css">
<script src="Radio_Button.js"></script>
</head>
<body>
<section>
<h1>Fun with Radio Buttonst</h1>
<form id="email_form" name="email_form" method="get">
<input type="radio" name="food1" id="cake1" value="cake" > Cake <br>
<input type="radio" name= "food2"id="muffns1"value="muffins" > Muffins <br>
<input type="radio" name= "food3"id="donuts1" value="donuts1" > hello <br>
<input type="radio" name="food4" id="food1" value="cookies" > Cookies<br>
<input type="submit" id="drink_selection" value="Process Drink Selection" onclick = "join_list()">
<br>
</form>
</section>
</body>
</html>
My JavaScript is as follows
var getsElement = function (id) {
return document.getElementById(id);
};
var join_list = function () {
getsElement("cake1").disabled = true;
getsElement("cake1").parentElement.disabled = true;
};
I can see the button disable when I watch the code but when the HTML reappears for user access the button is not disabled.
Your button reload the page, so your JS is missing. Also you should change your var join_list (scope var problems if you use this var in other functions like window.onload
) to function.
So your code should be
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Join Email List</title>
<link rel="stylesheet" target='_blank' href="Radio_Button.css">
<script src="Radio_Button.js"></script>
</head>
<body>
<section>
<h1>Fun with Radio Buttonst</h1>
<input type="radio" name="food1" id="cake1" value="cake"> Cake
<br>
<input type="radio" name="food2" id="muffns1" value="muffins"> Muffins
<br>
<input type="radio" name="food3" id="donuts1" value="donuts1"> hello
<br>
<input type="radio" name="food4" id="food1" value="cookies"> Cookies
<br>
<input type="submit" id="drink_selection" value="Process Drink Selection" onclick="join_list()">
</section>
</body>
</html>
JavaScript
var getsElement = function(id) {
return document.getElementById(id);
};
function join_list() {
getsElement("cake1").disabled = true;
getsElement("cake1").parentElement.disabled = true;
};
I'm new to HTML (just started learning at school) and I have a small question about classes and the ability to filter them. Basicially, I'm working on a page of football fixtures, which will look as ...
I'm new to HTML (just started learning at school) and I have a small question about classes and the ability to filter them. Basicially, I'm working on a page of football fixtures, which will look as ...
So, I'm not sure if I should've structured my app different or if I'm doing something fundamentally wrong. I'm a bit confused, but let's explain first things first. In the first navigation level, ...
So, I'm not sure if I should've structured my app different or if I'm doing something fundamentally wrong. I'm a bit confused, but let's explain first things first. In the first navigation level, ...
I'd like to build a website with a full height whatever the user's screen. Scroll is impossible, everything is shown in the page. I tried something like : <body> <div class="header"> ...
I'd like to build a website with a full height whatever the user's screen. Scroll is impossible, everything is shown in the page. I tried something like : <body> <div class="header"> ...
Html looks like this: <input class="car-type-input" name="carType[bmw]".../> How to get a variable in javascript which contains bmw using jQuery? Html CANT be changed! Current javascript: ...
Html looks like this: <input class="car-type-input" name="carType[bmw]".../> How to get a variable in javascript which contains bmw using jQuery? Html CANT be changed! Current javascript: ...