从表单生成文本

Generate text from forms

我正在尝试创建一个网站,用户只需检查收音机(是、否或未分配)即可生成或不生成某些文本。

例如,除了“Object1”之外还有 3 个无线电(是、否和未分配),除了“Object2”之外还有 3 个无线电,依此类推。

用户 select 如果一个人 has/doesn have/don 不知道它是否有 Object1,2,... 然后单击按钮生成一些文本:

“名称有 Object1,没有 Object2,有 Object4”。

现在我已经这样做了:

HTML

<div id="object1"> object1 :
<input id="object1yes" name="object1" type="radio"/>
<label for="object1yes">yes</label>
<input id="object1no" name="object1" type="radio"/>
<label for="object1no">no</label>
<input id="object1NA" name="object1" type="radio" checked="checked"/>
<label for="object1NA">NA</label>
</div>
<div>
<button id="generate" onclick="generate()">generate</button>
</div>
<div>
Person A <string id="Object1">
</div>

JAVA

function generate() {
 var checkObject1 = document.getElementById("object1");
 var text0 = "has object1";
 var text0 = "doesn't have object1";

我真的很纠结 Java :/ 我想做一些类似的东西

If (checkObject1yes.checked == true){
    display text0;
If (checkObject1no.checked ==true){
    display text1;
If (checkObject1NA.checked ==true){
   diplay none;

抱歉,如果不清楚并且草稿太多,我是编码新手:/

这可能对您有所帮助。

    <div id="object1"> object1 :
    <input id="object1yes" name="object1" type="radio" />
    <label for="object1yes">yes</label>
    <input id="object1no" name="object1" type="radio" />
    <label for="object1no">no</label>
    <input id="object1NA" name="object1" type="radio" checked="checked" />
    <label for="object1NA">NA</label>
</div>
<div>
    <button id="generate" onclick="generate()">generate</button>
</div>
<div id="Object1">
    Person A 
</div>

<script>
    function generate() {
        let name = document.getElementById('object1').innerText.split(":")[0];

        var text0 = "has object1";
        var text1 = "has object2";
        let none = "doesn't have any object";

        if(document.getElementById("object1yes").checked == true){
        document.getElementById("Object1").innerHTML = name+text0;
        }
    if(document.getElementById("object1no").checked == true){
            document.getElementById("Object1").innerHTML = name+text1;
        }
        if(document.getElementById("object1NA").checked == true){
            document.getElementById("Object1").innerHTML = name+none;
        }

        
    }
    
</script>