Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
change to a php variable in blade laravel doesn't persist

When I increment currentIndex whenever I click the next button, the value of currentIndex returns to its default value which is 1 here. So the update of currentIndex doesn't persist. Does anyone have any idea why? And how can I solve this problem?

    let inputBoxNum = 3
    let currentIndex
    {{ $currentIndex = 1 }}
    updateButtons()
    $('.back-btn, .next-btn').on('click', function (e) {
        console.log({{$currentIndex}}) // returns 1 even if this function was called before
        let btnClicked = e.target.className.includes('next-btn') ? 'next' : 'back'
        if (btnClicked === 'next') {
            {{$currentIndex += 1}} // it increments to 2
            console.log({{$currentIndex}}) // returns 2
            $('#create-input-box').html(`@include('reservations.create-input-box-'.$currentIndex)`)
        } else {
            $('#create-input-box').html(`@include('reservations.create-input-box-'.$currentIndex)`)
        }
        updateButtons()
    })
    function updateButtons() {
        getCurrentIndex()
        if (currentIndex <= 1) {
            $('.back-btn').hide()
            $('.next-btn').show()
        } else if (currentIndex > 1 && currentIndex < inputBoxNum) {
            $('.back-btn').show()
            $('.next-btn').show()
        } else {
            $('.back-btn').show()
            $('.next-btn').hide()
        }
    }

    function getCurrentIndex() {
        currentIndex = parseInt($('#create-input-box')[0].children[0].className.split("-")[3])
    }
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda