Home > Software engineering >  How can put a message of submitted form after a onclick button?
How can put a message of submitted form after a onclick button?

Time:02-02

I just need a pop up or a message saying 'thank you for submiting', but the onclick button to confirm is making that hard to do it

*Nome do Utilizador: 
        <div>
            <label for="email">*E-Mail: <span >&nbsp;</span></label>
            <input  id="email" maxlength="80" name="email" size="20" type="email" pattern="[a-z0-9._% -] @[a-z0-9.-] .[a-z]{2,63}$" /><br>
            
        </div>

        <div>
            <label for="Password__c">*Password:<span >&nbsp;</span></label>
            <textarea id="Password__c" name="Password__c"  required></textarea>
        </div>
        
        <div>
            <label for="Agent__c">*Responsável pelo pedido:<span >&nbsp;</span></label>
            <textarea id="Agent__c" name="Agent__c"  required></textarea>
        </div>
        
        <div>
            <label for="description">Descrição:<span >&nbsp;</span></label>
            <textarea id="description" name="description" ></textarea>
        </div>
    
        
        <p></p>

        <div >
            <span onclick="Alertasubmissao();">
            </span>     
            <input type="submit" name="submit" value="ENVIAR" onclick="return confirm('Tem a certeza que deseja enviar os dados ao cliente?');">

CodePudding user response:

You haven't wrote it in Javascript code and it's pretty difficult and gets your code messy if you trying to do it within HTML. It's better to make another file which is called for example: submitting.js and refer to is when clicked on the button.

<input type="submit" name="submit" value="ENVIAR" onclick="submitting,js">

In the submitting.js you should include the alert function of 'Javascript'. For example like this:

<script type="text/javascript">
    alert("You have clicked the button!");
</script>

CodePudding user response:

i hope this will help you, you need to move your confirmation and alert into a single function and call it when the form is submitted

if the user hit no to confirm Dialogue the form submission will be cancelled and if user hit confirm the form will be submitted and out thank you alert will be displayed.

document.querySelector('form').onsubmit = (e)=>{
 
  let okToSubmit = confirm('Tem a certeza que deseja enviar os dados ao cliente?');
  
  if(!okToSubmit) return false
  document.querySelector('.alert').innerText = "Thank you for submitting";
  return true;
  
}
<form action="/" method="post">
  <input type="text" name="name">
  <input type="submit"/>
</form>
<div ></div>

  •  Tags:  
  • Related