2017-07-29 7 views
0

チェックボックスをオンにすると、一連のテキストを読み込むことができません。以下のJSとHTML ...簡単な修正を探る - しかし、私はこれが機能していないことが失われている。 trainerexpjs HTMLチェックボックス

#wrap div#trainerexp 
{ 
    padding:10px; 
    font-weight:bold; 
    background-color:#ff0; 
} 

答えて

1

ため

// JS

function getTrainerExp() 

{ 
    var trainerexp="None"; 
    //Get a reference to the form id="courseform" 
    var theForm = document.forms["courseform"]; 
    //Get a reference to the checkbox id="includeexp" 
    var includeexp = theForm.elements["includeexp"]; 

    //If they checked the box set trainerexp to ACMEEXP 
    if(includeExp.checked==true) 
    { 
     trainerexp="ACMEXP"; 
    } 
    //return the trainer expenses 
    return trainerexp; 
} 


function calculateExp() 
{ 
    var expense = getTrainerExp() ; 

    //display the result 
    var divobj = document.getElementById('trainerexp').checked; 

    divobj.style.display='block'; 
    divobj.innerHTML = "Please Include " +expense; 

} 

HTML

<div id="wrap"> 
<form action="" id="courseform" onsubmit="return false;"> 
<div> 
<p> 
<label for='includeexp' class="inlinelabel">If course delivery is at customer site include trainer travel costs and expenses</label> 

<input type="checkbox" id="includeexp" name='includeexp' onclick="calculateExp()" /> 
</p> 

<div id="trainerexp"></div> 

CSSエントリのdocument.getElementByIdを使用しない理由は?

function getTrainerExp() 
 

 
{ 
 
    var trainerexp="None"; 
 
    //Get a reference to the form id="courseform" 
 
    var theForm = document.forms["courseform"]; 
 
    //Get a reference to the checkbox id="includeexp" 
 
    var includeExp = document.getElementById('includeexp'); 
 

 
    //If they checked the box set trainerexp to ACMEEXP 
 
    if(includeExp.checked==true) 
 
    { 
 
     trainerexp="ACMEXP"; 
 
    } 
 
    //return the trainer expenses 
 
    return trainerexp; 
 
} 
 

 

 
function calculateExp() 
 
{ 
 
    var expense = getTrainerExp() ; 
 

 
    
 
    document.getElementById("trainerexp").innerHTML = "Please Include " +expense; 
 

 
}
#wrap div#trainerexp 
 
{ 
 
    padding:10px; 
 
    font-weight:bold; 
 
    background-color:#ff0; 
 
}
<div id="wrap"> 
 
<form action="" id="courseform" onsubmit="return false;"> 
 
<div> 
 
<p> 
 
<label for='includeexp' class="inlinelabel">If course delivery is at customer site include trainer travel costs and expenses</label> 
 

 
<input type="checkbox" id="includeexp" name='includeexp' onclick="calculateExp()" /> 
 
</p> 
 

 
<div id="trainerexp"></div>

+0

これは働いていた - ポストに感謝 - 感謝を! :) – DudeNamedBen

+0

あなたは大歓迎です。この正解を見つけたら、答えとしてマークすることができます。 – zennith