function that wipes the VALUE of the field in the JSP

0

I need to insert a function in my JSP that clears the value of the input when the user clicks to enter the value, but I can not insert class into the input, nor is Placeholder accepted nor Onclick, could anyone tell me any way to do?

<%@taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<SCRIPT>
function verificarEEnviar()
{   
    var dsEmail=document.captacaoEmailsForm["dsEmail"].value;
    var atpos=dsEmail.indexOf("@");
    var dotpos=dsEmail.lastIndexOf(".");
        if (atpos<1 || dotpos<atpos+2 || dotpos+2>=dsEmail.length)
        {
            alert("Não é um endereço de e-mail válido");   
        }
        else{
            return document.captacaoEmailsForm.submit();
        }
        document.captacaoEmailsForm.reset();       
}
</SCRIPT>
<div class="captacao">
    <html:form action="/captacaoEmails" styleId="cadastroCliente2"> 
    <div class="captacao-titulo">Cadastre-se e receba<span> ofertas exclusivas </span> </div>
    <div class="captacao-email"> 

        <html:text tabindex="5" property="dsEmail" maxlength="60" onClick="this.form.reset()" value="inserir seu email" />
        <a href="javascript:verificarEEnviar();" id="btContinuar" class="captacao fr">Enviar</a>
        <br>
        <html:errors property="dsEmail" header="empty"/>
    </div>
    </html:form>
</div> 
    
asked by anonymous 03.10.2014 / 20:13

1 answer

1

I created the 'clearThis' function and called the field where I wanted it via 'onfocus="clearThis (this)' and it worked, I hope it helps anyone who needs it as well as helped me when the code worked.

<%@taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
  <%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <SCRIPT>
    document.dsEmail.reset();
    /*função valida email*/
    function verificarEEnviar()
    {   
        var dsEmail=document.captacaoEmailsForm["dsEmail"].value;
        var atpos=dsEmail.indexOf("@");
        var dotpos=dsEmail.lastIndexOf(".");
            if (atpos<1 || dotpos<atpos+2 || dotpos+2>=dsEmail.length)
            { alert("Não é um endereço de e-mail válido");
            }
            else{ return document.captacaoEmailsForm.submit(); }
        }
        function clearThis(target){
        target.value= "";
        }
    </SCRIPT>
     <div class="captacao">
        <html:form action="/captacaoEmails" styleId="cadastroCliente2"> 
        <div class="captacao-titulo">Cadastre-se e receba<span>ofertas exclusivas</span> </div>
        <div class="captacao-email"> 
            <html:text tabindex="5" property="dsEmail" maxlength="60" value="Digite seu E-mail" onfocus="clearThis(this)"/>
            <a href="javascript:verificarEEnviar();" id="btContinuar" class="captacao fr">Enviar</a>
            <br>
            <html:errors property="dsEmail" header="empty"/>
        </div>
        </html:form>
   </div> 
    
03.10.2014 / 22:09