Reputation: 383
I'm trying to write a script that disables a button depending on what the user entered on the previous page. However, I cannot even get the button to disable when I directly put disabled="disabled" into the input line. When I input the exact same code below on a .html page, it works fine and the button is disabled. I'm pretty new to web development, and I don't understand what's going on here. I specify <!DOCTYPE html>
and the button is within the <html>
tags. Any idea why this simple command wouldn't work?
<input type="button" id="b1" value ="How much can weight loss reduce my risk?" style="white-space:normal" disabled="disabled"/>
EDIT: All Code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm3.aspx.vb" Inherits="WebApplication2.WebForm3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="StyleSheet1.css" />
<title></title>
<style type="text/css">
#b1 {
height: 137px;
width: 137px;
}
</style>
</head>
<body>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(init);
function init() {
var data = google.visualization.arrayToDataTable([
['Years Out Risk', 'Risk'],
['5 Year Risk', <%= TKR5%>],
['10 Year Risk', <%= TKR10%>],
['15 Year Risk', <%= TKR15%>],
['20 Year Risk', <%= TKR20%>],
['25 Year Risk', <%= TKR25%>],
['30 Year Risk', <%= TKR30%>],
['Lifetime Risk', <%= TKRLife%>]
]);
var options = {
title: 'My Daily Activities',
'width': 400,
'height': 300,
animation: {
duration: 3000,
easing: 'out'
},
vAxis: {
viewWindowMode:'explicit',
viewWindow: {
max:1,
min:0
}
}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
var button1 = document.getElementById('b1');
var button2 = document.getElementById('b2');
function drawChart() {
button1.disabled = true;
button2.disabled = true;
google.visualization.events.addListener(chart, 'ready',
function () {
button1.disabled = false;
button2.disabled = false;
});
chart.draw(data, options);
}
button1.onclick = function () {
data.setValue(0, 1, <%= nobTKR5%>);
data.setValue(1, 1, <%= nobTKR10%>);
data.setValue(2, 1, <%= nobTKR15%>);
data.setValue(3, 1, <%= nobTKR20%>);
data.setValue(4, 1, <%= nobTKR25%>);
data.setValue(5, 1, <%= nobTKR30%>);
data.setValue(6, 1, <%= nobTKRLife%>);
drawChart();
};
button2.onclick = function () {
data.setValue(0, 1, <%= TKR5%>);
data.setValue(1, 1, <%= TKR10%>);
data.setValue(2, 1, <%= TKR15%>);
data.setValue(3, 1, <%= TKR20%>);
data.setValue(4, 1, <%= TKR25%>);
data.setValue(5, 1, <%= TKR30%>);
data.setValue(6, 1, <%= TKRLife%>);
drawChart();
}
drawChart();
}
</script>
<div id="chart_div"></div>
<input type="button" id="b1" value ="How much can weight loss reduce my risk?" style="white-space:normal" disabled="disabled"/>
<input type="button" id="b2" value ="Reset risk" style="white-space:normal"/>
</body>
</html>
Upvotes: 0
Views: 4634
Reputation: 391
if your button is HtmlButton
you can try with
myBtn.Attributes.Add("disabled","disabled");
it work for me.
Upvotes: 3
Reputation: 810
Try using < asp:Button id="b1" Text="Submit" disabled="disabled" runat="server" />
Upvotes: 0