Ajax: Do input para o html Imprimir E-mail


Esse exemplo de script imprime nesta página html o conteúdo que for digitado no campo input. Preencha algum texto no campo abaixo e clique no botão "submit".

Veja o exemplo em funcionamento:




Veja como é o código:

<script type="text/javascript" language="javascript">
    var lwefvvhttp_request = false;

    function exp2() {
        lwefvvhttp_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            lwefvvhttp_request = new XMLHttpRequest();
            if (lwefvvhttp_request.overrideMimeType) {
                lwefvvhttp_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                lwefvvhttp_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    lwefvvhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!lwefvvhttp_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
    var id = document.getElementById("exp2data").value;
    document.getElementById("exp2").innerHTML = id;
           
    }

</script>

 <input id="exp2data" type="text">
  <input value="Submit" onclick="javascript:exp2()" type="submit">
  <span id="exp2">
</span>


 
< Artigo anterior

web stats