2017-08-28 15 views
0

Ich arbeite an einer neuen Webseite zur Sicherheitsbewertung, in der ich HTML und Java Script verwende. Aus irgendeinem Grund funktioniert der Code nicht richtig und nicht die gewünschten Ergebnisse. Die Art, wie der Code arbeiten soll, ist, indem der Benutzer mit Ja oder Nein Fragen beantwortet, dann übergibt die Werte auf den 5 HTML-Seiten bis zur letzten Seite, wenn der Benutzer auf Senden klickt. Dann würde die Seite die Anzahl der beantworteten Fragen anzeigen.Übergeben von Radio Button-Werten von HTML-Seite zu HTML.

Jede Hilfe würde es geschätzt werden.

Danke,

<script> 
 
$('.calc').change(function() { 
 
    calcscore();    
 
}); 
 
$('#submitted').click(function() { 
 
    sumInputs(); 
 
    result(); 
 
}); 
 
function sumInputs() { 
 
    var inputs = $('.calc:checked'), 
 
     result = $('#total').val(), 
 
     sum = 0; 
 
    for (var i = 0; i < inputs.length; i++) { 
 
     sum += parseInt(inputs[i].value); 
 
    } 
 
    $('#total').val(sum); 
 
} 
 
function calcscore() { 
 
    var score = 0; 
 
    $('.calc:checked').each(function() {     
 
     score += parseInt($(this).val(), 10); 
 
    }); 
 
    $('#total').val(score); 
 
} 
 
</script> 
 

 
------------------------------------------------- 
 
(Last java script code) 
 

 
<script> 
 

 
$('.calc').change(function() { 
 
    calcscore();    
 
}); 
 

 
$('#submitted').click(function() { 
 
    sumInputs(); 
 
    result(); 
 

 
}); 
 

 
function sumInputs() { 
 
    var inputs = $('.calc:checked'), 
 
     result = $('#total').val(), 
 
     sum = 0; 
 

 
    for (var i = 0; i < inputs.length; i++) { 
 
     sum += parseInt(inputs[i].value); 
 
    } 
 
    $('#total').val(sum); 
 
} 
 

 
function result() { 
 
    var text; 
 
    var score = (($('#total').val())/57) * 100; 
 
    var score = score.toFixed(1);    
 

 
    if (score < 60) { 
 
     alert (text = "Total score " + score + ": You have failed the Assessment"); 
 
    } 
 
    else {    
 
     alert (text = "Total score " + score + ": You have passed the Assessment"); 
 
    } 
 

 
    $('#demo').text(text); 
 
} 
 

 
function calcscore() { 
 

 
    var score = 0; 
 

 
    $('.calc:checked').each(function() {     
 
     score += parseInt($(this).val(), 10); 
 
    }); 
 

 
    $('#total').val(score); 
 

 
} 
 

 
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 

 
\t \t <body> 
 
    <table> 
 
<th>PHYSICAL SECURITY </th> 
 
    
 

 
    <tr> 
 
    <td>7. Do you have policies and procedures that address allowing authorized and 
 
limiting unauthorized physical access to electronic information systems and the 
 
facilities in which they are housed? 
 

 
<form> 
 
Yes 
 
<input class="calc" type="radio" name="radio4" value="1" /> <br /> 
 
No 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 
N/A 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 

 
</form> 
 
</td> 
 
    </tr> 
 

 
    <tr> 
 
    <td>8. Do your policies and procedures specify the methods used to control physical 
 
access to your secure areas, such as door locks, access control systems, 
 
security officers, or video monitoring? 
 

 
<form> 
 
Yes 
 
<input class="calc" type="radio" name="radio4" value="1" /> <br /> 
 
No 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 
N/A 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 

 
</form> 
 
</td> 
 
    </tr> 
 
    
 
    </table> 
 
    
 
    </body> 
 
</html> 
 
--------------------------------------- 
 
Last html Page 
 
    
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 

 
<table> 
 
<tr> 
 
    <th>COMPLIANCE AND AUDIT</th> 
 
    
 
    </tr> 
 
    
 
    < 
 
    <tr> 
 
    <td>54. Do you review and revise your security documents, such as: policies, 
 
standards, procedures, and guidelines, on a regular basis? 
 
<form> 
 
Yes 
 
<input class="calc" type="radio" name="radio4" value="1" /> <br /> 
 
No 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 
N/A 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 

 
</form> 
 
</td> 
 
    </tr> 
 

 
    <tr> 
 
    <td>55. Do you audit your processes and procedures for compliance with established 
 
policies and standards? 
 

 
<form> 
 
Yes 
 
<input class="calc" type="radio" name="radio4" value="1" /> <br /> 
 
No 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 
N/A 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 

 
</form> 
 
</td> 
 
    </tr> 
 

 
    <tr> 
 
    <td>56. Do you test your disaster plans on a regular basis? 
 
<form> 
 
Yes 
 
<input class="calc" type="radio" name="radio4" value="1" /> <br /> 
 
No 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 
N/A 
 
<input class="calc" type="radio" name="radio4" value="0" /> <br /> 
 

 
</form> 
 
</td> 
 
    </tr> 
 

 
    </table> 
 

 
<a href="secEdu.html" class="previous">&laquo; Previous</a> 
 
<input type="hidden" name="total" id="total" /> 
 
    <input id="submitted" type="Submit" value="Submit"><br><br> 
 
    <p id="demo"></p> 
 

 
</body> 
 
</html> 
 
    
 

+0

Alle Ihre Optionsfelder haben denselben Namen und gehören somit zur selben Gruppe. – Barmar

+0

* "Übergeben Sie die Werte an die 5 HTML-Seiten" * - Wie erreichen Sie dies derzeit? – Santi

+0

Wenn Sie die Seite ändern, ohne das Formular zu senden, müssen Sie es in einem Cookie oder einer anderen lokalen Variablen speichern. Vielleicht möchten Sie das Ausblenden und Anzeigen von Fieldsets in Etappen und das Senden von EINER einzelnen HTML-Seite in Betracht ziehen. Google Multi-Step-Formular gibt es Tonnen von jQuery Beispiele – happymacarts

Antwort

0

Shop in localstorage und sie von allen anderen Seiten. Beispiel: localstorage.setItem("RadioVal",'true');

aus lokalen Speicher in anderen Skripts erhalten und in entsprechenden HTML-Felder zuweisen. Beispiel: var radio1 = localstorage.getItem("RadioVal");

Verwandte Themen