Rempcer un input par un select
simachille
Messages postés
64
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
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
[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
A voir également:
- Rempcer un input par un select
- Please select boot device ✓ - Forum Windows
- Input signal not found ✓ - Forum Matériel & Système
- Input not supported - Forum Ecran
- Please select boot device - Forum Matériel & Système
- No video input - Forum Windows
1 réponse
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>