Click here to Skip to main content
15,881,380 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Peter_in_278027-Mar-21 0:54
professionalPeter_in_278027-Mar-21 0:54 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 21:40
Member 1501261727-Mar-21 21:40 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 22:49
Member 150126178-Apr-21 22:49 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Richard Deeming28-Mar-21 22:29
mveRichard Deeming28-Mar-21 22:29 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 22:49
Member 150126178-Apr-21 22:49 
QuestionRedirect with (Page Visibility API) Pin
ab smine19-Mar-21 10:38
ab smine19-Mar-21 10:38 
QuestionNode-Schedule Module Can't Cron Job Scheduled Long Time Pin
Barış KAHRAMAN19-Mar-21 10:02
Barış KAHRAMAN19-Mar-21 10:02 
QuestionCalculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 3:31
Krasimir Dermendzhiev16-Mar-21 3:31 
Hello,

I'm trying to calculate values every time when change it.

<pre lang="HTML"><pre><ol class="firstDigit"> 
    <li data-value="10"> 10 </li>


and
HTML
<pre><ol class="secondDigit"> 
    <li data-value="10"> 10 </li>

The sum is 20. The problem is when I change firstDigit or secondDigit to 20
HTML
<pre><ol class="firstDigit"> 
    <li data-value="20"> 20 </li> 

The sum is 40, but should be 30.
JavaScript
const firstNav = $('#firsNav');
const firstSelection = $('.firstDigit'); 
const firstValue = firstSelection.find('li');  
const secondNav = $('#secondNav'); 
const secondSelection = $('.secondDigit'); 
const secondValue = secondSelection.find('li') 
var sum = 0; 
firstNav.click(function(event) {   
    if (firstNav.hasClass('active')) {     
        firstNav.removeClass('active');     
        selection.stop().slideUp(200);   
    } else {     
            firstNav.addClass('active');     
            selection.stop().slideDown(200);
    }   
        event.preventDefault(); 
});  
secondNav.click(function(event) {   
    if (secondNav.hasClass('active')) {     
        secondNav.removeClass('active');     
        secondSelection.stop().slideUp(200);   
    } else {     
        secondNav.addClass('active');     
        secondSelection.stop().slideDown(200);   
    }   
    event.preventDefault(); 
});  
firstValue.click(function() {   
    firstValue.removeClass('active');   
    $(this).addClass('active');   
    var x = $(this).attr('data-value');   
    sum = parseInt(x);   
    document.getElementById('total').innerHTML = sum; });  
    firstValue.click(function() {   
    firstValue.removeClass('active');   
    $(this).addClass('active');   
    var z = $(this).attr('data-value');   
    sum = parseInt(z);   
    document.getElementById('total').innerHTML = sum; 
})  
document.getElementById('total').innerHTML = sum;

HTML
<pre><h2 id="firsNav">Choose</h2> 
<ol class="firstDigit"> 
    <li data-value="10"> 10 </li>
    <li data-value="20"> 20 </li>
</ol>
<h2 id="secondNav">Choose</h2>
<ol class="secondDigit"> 
    <li data-value="10"> 10 </li> 
    <li data-value="20"> 20 </li> 
</ol> 
<a id="total" style="font-size: large;font-weight: bold;color: #0a0a0a"></a>

AnswerRe: Calculation in javascript Pin
Richard Deeming16-Mar-21 4:39
mveRichard Deeming16-Mar-21 4:39 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 21:36
Krasimir Dermendzhiev16-Mar-21 21:36 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev30-Mar-21 4:22
Krasimir Dermendzhiev30-Mar-21 4:22 
QuestionJavascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027614-Mar-21 21:50
Member 1510027614-Mar-21 21:50 
AnswerRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming14-Mar-21 22:39
mveRichard Deeming14-Mar-21 22:39 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027614-Mar-21 23:11
Member 1510027614-Mar-21 23:11 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming14-Mar-21 23:29
mveRichard Deeming14-Mar-21 23:29 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 7:56
Member 1510027615-Mar-21 7:56 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 22:31
mveRichard Deeming15-Mar-21 22:31 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027616-Mar-21 6:49
Member 1510027616-Mar-21 6:49 
Questionif statement not working Pin
chizzy4211-Mar-21 7:53
chizzy4211-Mar-21 7:53 
AnswerRe: if statement not working Pin
NotTodayYo11-Mar-21 8:24
NotTodayYo11-Mar-21 8:24 
AnswerRe: if statement not working Pin
W Balboos, GHB11-Mar-21 8:45
W Balboos, GHB11-Mar-21 8:45 
GeneralRe: if statement not working Pin
chizzy4213-Mar-21 4:03
chizzy4213-Mar-21 4:03 
GeneralRe: if statement not working Pin
Member 1510027615-Mar-21 8:15
Member 1510027615-Mar-21 8:15 
GeneralRe: if statement not working Pin
chizzy4217-Mar-21 2:28
chizzy4217-Mar-21 2:28 
QuestionBeginner 5 Project idea Pin
Member 1373246628-Feb-21 14:29
Member 1373246628-Feb-21 14:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.