Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the statements to create a new XMLHttpRequest object. Then create the requ

ID: 3582525 • Letter: W

Question

Write the statements to create a new XMLHttpRequest object. Then create the request such that it will use a POST. http://forecast.weather.gov/MapClick.php?lat39.3233&lon=-120.3797UNIT=0&LG=ENGLISH&fCSTtYPE=DWML. the reuest should be performed synchronously.

Assume that there are two text input elements named input1 and input2, write the javascript code to get the value from these two elements and convert them to numeric values. Then add the two values together and store the result in the InnerHTML of the paragraph having an ID of output. Verify that both input values contain numbers. display a message in another control(abel) if the input is not valid.

Explanation / Answer

1.
var http = new XMLHttpRequest();
var url = "http://forecast.weather.gov/MapClick.php?lat39.3233&lon=-120.3797UNIT=0&LG=ENGLISH&fCSTtYPE=DWML";
http.open("POST", url, true);

2.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function addFunction (){
var n1 = parseInt(document.getElementById("input1").value);
var n2 = parseInt(document.getElementById("input2").value);
var total = n1+n2;
document.getElementById("result").innerHTML = total.toString();
}
function checkInp()
{
var x=document.getElementById("input1").value;
var y=document.getElementById("input2").value;
if (isNaN(x) || isNaN(y))
{
alert("Must input numbers");
return false;
}else{
addFunction();
return true;
}
}
</script>
</head>
<body>
<label> Input1 : </label><input id="input1" name="input1" type="text"></br></br>
<label> Input2 : </label><input id="input2" name="input2" type="text"></br></br>
<button>Click me</button>
</br></br>
result :
<p id="result">
</p>
  
</body>
</html>