Jump to content
Fórum Script Brasil
  • 0

formulario


Question

Boas, alguém ajudar a criar script de verificar checkbox e radio e o value das opçoes do checkbock e radio é escrito para ficheiro txt.

 

<DOCTYPE html>
<html>
<head>
<title>  frequencia1 </title>
<link rel="stylesheet" type="text/css"  href="./frequencia1.css"  />
</head>
<body>
<h2>Ficha de Encomenda de Pizzas</h2>

<form>
<p>Qual a Pizza a encomendar? 
 <select name="pizza1" id="pizza">
   <option value="" selected disabled hidden></option>
   <option value="Fiambre com cogumelos">Fiambre com cogumelos</option>
   <option value="Bacon com fiambre">Bacon com fiambre</option>
   <option value="Queijo com cogumelos">Queijo com cogumelos</option>
 </select>
 Quantidade:
 <select name="quantidade11" id="quantidade1">
   <option value="" selected disabled hidden>0</option>
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
 </select>
</p>
</form>

<form>
<p>
Qual a bebida?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="bebida1" id="bebida">
   <option value="" selected disabled hidden></option>
   <option value="CocaCola">CocaCola</option>
   <option value="Ice Tea Limão">Ice Tea Limão</option>
   <option value="Fanta Laranja">Fanta Laranja</option>
 </select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Quantidade:
<select name="quantidade22" id="quantidade2">
   <option value="" selected disabled hidden>0</option>
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
 </select>
</p>
</form>

<form name="opcoes1" id="opcoes">
<input type="checkbox" id="opcao" name="opcao" value="Extra Queijo"> Extra Queijo
<input type="checkbox" id="opcao" name="opcao" value="Massa Grossa"> Massa Grossa
<input type="checkbox" id="opcao" name="opcao" value="Pimentos"> Pimentos
<input type="checkbox" id="opcao" name="opcao" value="Cogumelos"> Cogumelos
</form>

<hr></hr>

<p><b>Dados para <br> entrega</b></p>
<form>
<p> Nome: 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="nome1" id="nome" size="50" value="">
Morada:
<input type="text" name="morada1" id="morada" size="40" value=""> </p>
<p> Telefone: 
&nbsp;&nbsp;
<input type="text" name="telefone1" id="telefone" value=""> </p>
</form>

<hr></hr>

<p><b> Forma de pagamento </b></p>
<form name="pagamento11" id ="pagamento">
<input type="radio" id="pagamento1" value="VISA"> VISA
<input type="radio" id="pagamento2" value="Contra Entrega"> Contra Entrega 
<input type="radio" id="pagamento3" value="Factura"> Factura(30 dias, +15%)<br>
<p>Número do cartão VISA
<input type="text" name="visa11" id="visa1" size="20" value=""> </p>
</form>

<hr></hr>

<button onclick="saveTextAsFile()" id="inputFileNameToSaveAs">Enviar!</button>
<button onclick="limpa1" >Limpar</button>

<script>
    
    
function saveTextAsFile(){
            var textToWrite = document.getElementById("pizza").value + " " + document.getElementById("quantidade1").value + "\n" +
            document.getElementById("bebida").value + " " + document.getElementById("quantidade2").value + "\n" +
            document.getElementById("opcoes").value + "\n" + 
            document.getElementById("nome").value + "\n" + 
            document.getElementById("morada").value + "\n" + 
            document.getElementById("telefone").value + "\n" + 
            document.getSelection("radio").value + "\n" + 
            document.getElementById("visa1").value;
            var textFileAsBlob = new Blob([textToWrite],{type:'text/plain'});
            var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
            var downloadLink = document.createElement("a");
            downloadLink.download = fileNameToSaveAs;
            downloadLink.innerHTML = "Dowmload File";
            if(window.webkitURL !=null){downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);}
                   downloadLink.click();
             } 
</script>
</body>
</html>

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148680
    • Total Posts
      644501
×
×
  • Create New...