Html to json

generateJson: function(idTag) { var json = "{"; $('#' + idTag + ' input, ' + '#' + idTag + ' select').each(function() { if(!$(this).prop('disabled')) { if($(this).is(':radio')) { if($(this).prop('checked') == true) json += ('"' + this.name + '":' + '"' + this.value + '",') } else if($(this).is('select')) { json += ('"' + this.name + '":' + '"' + $(this).find('option:selected').val() + '",') } else json += ('"' + this.name + '":' + ((this.value) ? '"' + this.value.replace('-', '') + '"' : null) + ',') } }); json = json.substring(0, json.length-1) + '}'; return json; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.