Rempcer un input par un select

Fermé
simachille Messages postés 64 Date d'inscription jeudi 2 avril 2009 Statut Membre Dernière intervention 4 octobre 2011 - 2 mai 2011 à 12:26
 Utilisateur anonyme - 5 mai 2011 à 23:18
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

Utilisateur anonyme
5 mai 2011 à 23:18
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