jquery’s maskMoney function does not work in div loaded via ajax

Asked

Viewed 181 times

0

I have a page I’m refreshing with ajax only in the div conteúdo. It is configured like this:

div1: I load 2 selects where the user will choose these 2 data (class and bimonthly)

div 2: I load the application menu (.php menu) end of div 2

div id="content": I load the page that reads the 2 selects and load the corresponding php page, according to the item chosen in the menu at div2 end of div id="conteudo"

On the main page, where I have all these Divs, I use the function maskMoney jquery to mask my inputs only as decimal numbers. When I put an input into the upper Ivs (1 and 2) maskMoney works perfectly. When an input is loaded by ajax into the contents div, the maskMoney doesn’t work.

Could someone help me understand why this occurs and how to solve?

  • put your code so that forum users can help you in the best way

1 answer

0


Hi, Regina Apparently it’s only working on div’s that don’t use ajax because you must have used the jquery Mask styling command at the time your page loads. It is now necessary to re-enter the plugin function

Try to add the code that applies the mask to the component again at the moment it gets the return of the ajax query, this should solve your problem.

Edited:

Code:

function AlteraConteudo() {
    var ajax = AjaxF();
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4) {
            document.getElementById('conteudo').innerHTML = ajax.responseText;
            //Aqui você executa os comandos do plugin novamente
        }
    };
    dados = "classe=" + document.getElementById('classes').value + "&bimestre=" + document.getElementById('bimestre').value + "&ano=" + document.getElementById('ano').value + "&tipo=" +document.getElementById('tipo').value;
    var pagina = document.getElementById('pagina').value;
    ajax.open("GET", pagina + dados, false);
    ajax.setRequestHeader("Content-Type", "text/html");
    ajax.send();
}

Att

Bruno Miquelotto

  • I understood the logic Bruno. makes perfect sense and that must be it. The function of the mask is rotated in $(Document). ready(Function(){, which I think means the full page load, isn’t it??

  • Post your ajax code here for us to see

  • // Function that checks if the browser supports AJAX Function Ajaxf() { var ajax; Try { ajax = new Xmlhttprequest(); } catch(e) { Try { ajax = new Activexobject("Msxml2.XMLHTTP"); } catch(e) { Try { ajax = new Activexobject("Microsoft.XMLHTTP"); } catch(e) { Alert("Your browser does not support AJAX!"); Return false; } } } Return ajax; } ;//

  • I’m sorry, but I can’t move right here. Did the code look really bad? I couldn’t find how to attach a file here in the post

  • The code snippet is just this ? Because this code does not make the request, it just checks if the browsed supports ajax

  • Function Alteracontentudo() { var ajax = Ajaxf(); ajax.onreadystatechange = Function(){ if(ajax.readyState == 4) { Document.getElementById('contents'). innerHTML = ajax.responseText; } } var data = "class="+Document.getElementById('classes'). value+"&bimestre="+Document.getElementById('bimestre'). value+"&ano="+Document.getElementById('year'). value+"&type="+Document.getElementById('type'). value; var pagina = Document.getElementById('pagina'). value; ajax.open("GET", page + data, false); ajax.setRequestHeader("Content-Type", "text/html"); ajax.send(); }

  • this part of the code was missing...

  • I’ll try to do it and whenever I come back here. Thank you

  • Thank you very much. It was right. Hugs

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.