Reputation: 19
This is some of the coding I have. I wanted to make the statements print directly on the page instead of using alert or document.write. I tried to use getElementId but it isnt working that great for me, I tried it on the first line in the script. The others are still an alert. Help?
<body>
<div id="myDiv1"></div>
<div id="myDiv2"></div>
Select one:<br>
<form name="locationform">
<input type="checkbox" name="North">North <br>
<input type="checkbox" name="South">South<br>
<input type="checkbox" name="Equator">Equator<hr>
Select another one:<br>
<input type="checkbox" name="Inward">Inward<br>
<input type="checkbox" name="Outward">Outward<br><br>
<input type="button" value="Submit" name="myButton" onClick="myfunction()">
<button type="reset" value="Reset">Reset</button>
</form>
<script language="JavaScript">
function myfunction() {
***if((document.locationform.North.checked == true) && (document.locationform.Inward.checked == true)){
document.getElementById('myDiv1').innerhtml = 'Some Test';***
}else if((document.locationform.South.checked == true) && (document.locationform.Outward.checked == true)){
alert("Case 4.");
}else if((document.locationform.Equator.checked == true) && (document.locationform.Outward.checked == true)){
alert("Case 6.");
}else if((document.locationform.South.checked == true) && (document.locationform.Inward.checked == true)){
alert("Case 3.");
}else if((document.locationform.North.checked == true) && (document.locationform.Outward.checked == true)){
alert("Case 5.");
}else if((document.locationform.Equator.checked == true) && (document.locationform.Inward.checked == true)){
alert("Case 2.");
} else if((document.locationform.Inward.checked == false) && (document.locationform.Outward.checked == false)){
alert("Select a valid entry");
} else if((document.locationform.North.checked == true) && (document.locationform.South.checked == true)){
alert("Select a valid entry");
} else if((document.locationform.North.checked == true) && (document.locationform.Equator.checked == true)){
alert("Select a valid entry");
} else if((document.locationform.Equator.checked == true) && (document.locationform.South.checked == true)){
alert("Select a valid entry");
}
</script>
Upvotes: 0
Views: 46
Reputation: 17703
It's innerHTML
not innerhtml
.
e.g. document.getElementById('mainbar').innerHTML
Upvotes: 0
Reputation: 2051
HTML
<div id="write_here"></div>
JS:
document.getElementById('write_here').innerHTML = 'Print Text Here';
Upvotes: 1
Reputation: 26434
You have a bug in your code
document.getElementById('myDiv1').innerhtml = 'Some Test';
should be
document.getElementById('myDiv1').innerHTML = 'Some Test';
Test it out in your console. element.innerhtml
will return undefined
because that is not a method.
Here's the source
http://www.w3schools.com/jsref/prop_html_innerhtml.asp
Upvotes: 1