Home

Javascript All Form Elements To JSON

<form action="/" id="myForm" method="post">

<input id="address_line_1" type="text" />
<br />

<input id="address_line_2" type="text" /> 
<br />

<input id="address_line_3" type="text" />        
<br />

<input id="post_code" type="text" />        
<br />
        
<a href="#" onclick="go()">Go</a>

 

<script>

    function go(){
        var myAll = document.getElementById('myForm')
        var jsonBuilderObject = {}

        for(var i = 0; i < myAll.length; i++){
            jsonBuilderObject[myAll[i].id] = myAll[i].value
        }

        var json=JSON.stringify(jsonBuilderObject)
        console.log(json)
    }

</script>

Reader's Comments

Post Your Comment Posts/Links Rules

Name

Comment

Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below




Home
Admin Ren's Biking Blog