Rempcer un input par un select

simachille Messages postés 79 Statut Membre -  
 Utilisateur anonyme -
Bonjour j'ai ce code qui me permet de generer un fichier en javascript qui contient les données inserées d'un formulaire il fonctionne sans problème

[code]<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Form saving</title>
</head>
<body>

<form onsubmit="saveForm(this); return false;">
<input type=text name="myInputBox"><br>
<input type=text name="myOtherField"><br>
<input type=submit value="Generate download link">
</form>

<a href="data:multipart/alternative;charset=utf-8," id="downloadLink">Rightclick, save as</a>

<script>

function saveForm(form) {
var dlLink = document.getElementById('downloadLink');
var datastring = "Field 1: "+form.myOtherField.value+"\n"+"Field 2: "+form.myInputBox.value;
dlLink.href = 'data:multipart/alternative;charset=utf-8,'+encodeURIComponent(datastring);
};

</script>
</body>
</html>/code

J'aimerais remplacer les input test par des select
Mais ça me reset le formulaire

Merci de me proposer une solution

1 réponse

  1. Utilisateur anonyme
     
    Salut, voici ma réponse, j'espère t'aider :

    <html>
    <head>
    <meta charset="utf-8">
    <title>Form saving</title>
    </head>
    <body>
    
    <form onsubmit="saveForm(this); return false;">
    <select name="myInputBox">
    <option value="myInputBox">myInputBox</option>
    <option value="myOtherField">myOtherField</option>
    </select><br />
    <input type="button" value="Generate download link">
    </form>
    
    <a href="data:multipart/alternative;charset=utf-8," id="downloadLink">Rightclick, save as</a>
    
    <script>
    
    function saveForm(form) {
    var dlLink = document.getElementById('downloadLink');
    var datastring = "Field 1: "+form.myOtherField.value+"\n"+"Field 2: "+form.myInputBox.value;
    dlLink.href = 'data:multipart/alternative;charset=utf-8,'+encodeURIComponent(datastring);
    };
    
    </script>
    </body>
    </html>
    
    0