0
What is wrong in my code? I don't know javascript well so can anyone help me?
There are two ratio groups when you choose something in the first ratio group there is a number should appear and when you choose something in the second ratio group anther number will appear and when the user click on submit button two numbers will sum and appear in textarea. https://code.sololearn.com/WKSXIkOKYfwl/?ref=app
4 Respostas
+ 6
<!-- Here you are -->
<!DOCTYPE html>
<html>
<head>
<title>number for word</title>
<script>
function nameChoose(value){ document .getElementById("dynamicA").innerHTML=value;
}
function schoolChoose(value){ document .getElementById("dynamicB").innerHTML=value;
}
function text(){
a=document .getElementById("dynamicA").innerHTML ;
b=document .getElementById("dynamicB").innerHTML ;
document.getElementById ("my").innerHTML =Number(a)+ Number(b);
}
</script>
</head>
<body>
<form>
<p id="dynamicA" style="display:none">0</p>
<p id="dynamicB" style="display:none">0</p>
<textarea id="my"></textarea>
<p>What is your name</p>
<input type="radio" name="name" value ="1" id ="a" onclick= "nameChoose(this.value);" />krio
<input type="radio" name="name" value ="2" id ="a" onclick= "nameChoose(this.value);" />ayman
<input type="radio" name="name" value ="3" id ="a" onclick= "nameChoose(this.value);" />mohamed
<input type="radio" name="name" value ="4" id ="a" onclick= "nameChoose(this.value);" />halim
<input type="radio" name="name" value ="5" id ="a" onclick= "nameChoose(this.value);" />mariam
</form>
<form>
<p>What is your school</p>
<input type="radio" name="school" value ="1" id ="b" onclick="schoolChoose(this.value);" />future
<input type="radio" name="school" value ="2" id ="b" onclick="schoolChoose(this.value);" />glil
<input type="radio" name="school" value ="3" id ="b" onclick="schoolChoose(this.value);" />magdy
<input type="radio" name="school" value ="4" id ="b" onclick="schoolChoose(this.value);" />san gorgre
<input type="radio" name="school" value ="5" id ="b" onclick="schoolChoose(this.value);" />san mary
</form>
<button onclick="text()">submit</button>
</body>
</html>
+ 5
Ok, I've checked it, I found a syntax error, Javascript is sensitive so A and a is different. In your code, line 20, you have to change Var to var.
function text(){
document.getElementById("my")
.innerHTML+="sum";
}
function done(){
var a = document .getElementById ('a');
var b = document .getElementById ('b');
var sum = document .getElementById ('sum');
var a = a.value;
var b = b.value ;
var sum = a + b;
var sum = document .getElementById ("my");
}
0
Thank you very much but I try it and when I click on the submit button word sum appears in the textarea not the actual sum of two numbers
0
Thank you