Reputation: 41
Hello i wanna ask how can i make a radio button from input and button
Html
<input type="text" id="no" placeholder="No Soal">
<select id="nilai">
<option value="1">Benar</option>
<option value="0">Salah</option>
</select>
<input type="text" id="val" placeholder="Pilihan">
<button onclick="myFunctions()">Judul</button>
Javascript
<script>
function myFunctions() {
var x = document.getElementById("no").value;
var y = document.getElementById("nilai").value;
var z = document.createElement("INPUT");
z.setAttribute("type", "radio");
z.setAttribute("name", x);
z.setAttribute("value", y)
document.body.appendChild(z);
}
</script>
I wanna get value from text id val and show it in <input type="radio" name="1" value="0">HERE
can anyone help?
Upvotes: 2
Views: 80
Reputation: 1084
you can achieve it by below code
var v = document.getElementById("val").value;
var text = document.createTextNode('id='+v);
document.body.insertBefore(text,z.nextSibling);
Upvotes: 1