Created
March 13, 2019 11:36
-
-
Save vqoph/20a1ac0861a6dc16f7b92e0282efc760 to your computer and use it in GitHub Desktop.
Batch users // source https://jsbin.com/naporuw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Batch users</title> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="container"> | |
<form> | |
<div class="row"> | |
<div id="formTemplate" class="col-md-6 mb-3"> | |
<div class="form-group"> | |
<label for="result">Combien font 2+2</label> | |
<input type="text" class="form-control" name="result"> | |
</div> | |
<hr> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-12"> | |
<input type="submit" class="btn btn-primary"> | |
</div> | |
</div> | |
</form> | |
</div> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<script id="jsbin-javascript"> | |
// External jquery plugin | |
// https://gist.github.com/rambabusaravanan/8eebfd7a9c828fd6121c8d8a48e08962 | |
$.fn.serializeObject = function() { | |
var obj = {}; | |
var arr = this.serializeArray(); | |
arr.forEach(function(item, index) { | |
if (obj[item.name] === undefined) { // New | |
obj[item.name] = item.value || ''; | |
} else { // Existing | |
if (!obj[item.name].push) { | |
obj[item.name] = [obj[item.name]]; | |
} | |
obj[item.name].push(item.value || ''); | |
} | |
}); | |
return obj; | |
}; | |
$(document).ready(() => { | |
$('form').submit(e => { | |
const formData = | |
$(e.currentTarget).serializeObject() | |
alert(formData.result === 4); | |
e.preventDefault(); | |
}); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
// External jquery plugin | |
// https://gist.github.com/rambabusaravanan/8eebfd7a9c828fd6121c8d8a48e08962 | |
$.fn.serializeObject = function() { | |
var obj = {}; | |
var arr = this.serializeArray(); | |
arr.forEach(function(item, index) { | |
if (obj[item.name] === undefined) { // New | |
obj[item.name] = item.value || ''; | |
} else { // Existing | |
if (!obj[item.name].push) { | |
obj[item.name] = [obj[item.name]]; | |
} | |
obj[item.name].push(item.value || ''); | |
} | |
}); | |
return obj; | |
}; | |
$(document).ready(() => { | |
$('form').submit(e => { | |
const formData = | |
$(e.currentTarget).serializeObject() | |
alert(formData.result === 4); | |
e.preventDefault(); | |
}); | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// External jquery plugin | |
// https://gist.github.com/rambabusaravanan/8eebfd7a9c828fd6121c8d8a48e08962 | |
$.fn.serializeObject = function() { | |
var obj = {}; | |
var arr = this.serializeArray(); | |
arr.forEach(function(item, index) { | |
if (obj[item.name] === undefined) { // New | |
obj[item.name] = item.value || ''; | |
} else { // Existing | |
if (!obj[item.name].push) { | |
obj[item.name] = [obj[item.name]]; | |
} | |
obj[item.name].push(item.value || ''); | |
} | |
}); | |
return obj; | |
}; | |
$(document).ready(() => { | |
$('form').submit(e => { | |
const formData = | |
$(e.currentTarget).serializeObject() | |
alert(formData.result === 4); | |
e.preventDefault(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment