Editing page content via JQuery and leaving it fixed

2

I would like to know the method of editing the page and leave the content I've edited fixed there forever, as if it were a post.

I've tried this:

<style type="text/css">
.aprovado{
    background-color: #060;
    color: #FFFFFF;
}
.reprovado{
    background-color: #f22;
    color: #E2E2E2;
}
</style>
    < script type="text/javascript" src="jquery-min.js"></script>
    < script type="text/javascript">
$(function(){

    $("#btn").click(function(){

        $("#resposta").removeClass();

        var nome = $("#txtnome").val();
        var n1 = parseFloat ($("#txtn1").val());
        var n2 = parseFloat ($("#txtn2").val());

        var media = (n1 + n2) / 2;           
        $("#resposta").html(nome + ", " + media);

        if(media >= 7){
            $("#resposta").addClass("aprovado");
        }else{
            $("#resposta").addClass("reprovado");
        }


    });

});
</script>
<h3>Ver Dados do Aluno</h3>
<form>
Nome: <input type="text" name="nome" id="txtnome" />
<br /><br />
Nota1: <input type="text" name="n1" id="txtn1" />
<br /><br />
Nota2: <input type="text" name="n2" id="txtn2" />
<br /><br />
<input type="button" value="Enviar Dados" id="btn" />
</form>
<div id="resposta"></div>

It works, but when updating the page some, but how do I save the changes just using AJAX and jQuery?

    
asked by anonymous 03.03.2014 / 18:37

2 answers

2

Hello, I understand that you are trying to edit HTML content with just Javascript, but what you wanted to do is record an important data such as a flag saying that the student is approved or disapproved.

I'm sorry but you will need to use some feature to write this data, like a Database, and to interact with it you can not use just Javascript needing the use of some other language like PHP, Ruby, etc. >

Javascript works only in the browser, this update you are making is visible in the browser but no record is recorded somewhere to identify whether the student is approved or not, if you want to perform the update in this way, however you will have to use another resource, such as Ajax, which would send that information to another page, in PHP for example, and it would perform the update on your DB.

Good luck, my friend.

    
03.03.2014 / 23:49
1

If you want to save the changes to be read later anywhere you link to your web page, you have to do what matheus_auler said. If you only need this in a browser for a short time, you can use HTML5 - Local Storage . With it you will save the data in the browser / browser and you will not be able to access it from another location.

    
04.03.2014 / 15:33