- Joined
- Dec 10, 2022
- Messages
- 17
- Reaction score
- 2
Dear friends,
Could someone help me to fix this code? I want fill up the data manually instead using the fixed data
Regards
Could someone help me to fix this code? I want fill up the data manually instead using the fixed data
JavaScript:
<script>
function onClick(elem)
var data = [
['1970', a], ['1980', e], ['1990', i] ,
['2000', d], ['2010', h], ['2020', m]
];
var ax = document.getElementById("a").value;
var dx = document.getElementById("d").value;
var ex = document.getElementById("e").value;
var hx = document.getElementById("h").value;
var ix = document.getElementById("i").value;
var mx = document.getElementById("m").value;
var a = ax.value; //How to treat an input data as variables
var d = dx.value;
var e = ex.value;
var h = hx.value;
var i = ix.value;
var m = mx.value;
document.write('<img src="http://chart.apis.google.com/chart?'
+ 'chs=500x400'
+ '&cht=p3'
+ '&chco=33ff00'
+ '&chd=t:');
for (var i=0; i < data.length; ++i) {
document.write(data[i][1]);
if (i < data.length-1) document.write(",");
}
document.write('&chxt=x,y');
document.write('&chxl=0:|');
for (var i=0; i < data.length; ++i) {
document.write(data[i][0]);
if (i < data.length-1) document.write("|");
}
document.write('&chxr=1,0,100');
document.write('">');
}
</script>
HTML:
<form id='data'>
<input type="text" id="a" value="" />
<input type="text" id="d" value="" />
<input type="text" id="e" value="" />
<input type="text" id="h" value="" />
<input type="text" id="i" value="" />
<input type="text" id="m" value="" />
<input type='submit' id='data' onclick="onClick();">
</form>
Regards
Last edited: