I have a function ipcfg_set that will set the IP address and it takes the user input variable and sends it in JSON format back to the function. Having issue with constructing the script that takes the IP,mask,gateway entered by user and upon clicking the button will send the value in JSON back.
function ipcfg_set ()
{
$.ajax({
type: 'POST',
url: 'ipcfg_set.cgi',
dataType : "json",
data: { ipv4_addr: $('#ip1').val() + '.' + $('#ip2').val() + '.' + $('#ip3').val() + '.' + $('#ip4').val(),
gw_addr: $('#gw1').val() + '.' + $('#gw2').val() + '.' + $('#gw3').val() + '.' + $('#ip4').val(),
ipv4_mask: $('#nm1').val() + '.' + $('#nm2').val() + '.' + $('#nm3').val() + '.' + $('#nm4').val()
}
success: function(data) {
});
}
$(function() {
$('#btnreset').on('click', ipcfg_get);
$('#btnapply').on('click', ipcfg_set);
ipcfg_get();
});
HTML code
<section>
<h2>IP Configuration</h2>
<p>Please fill in the form and press <b>Apply</b> to save settings.</p>
<p>Press <b>Reset</b> to revert settings.</p>
<section>
<table class="formgrid">
<tr><th>IP Address:</th><td><input type="text" name="a1" id="ip1" size="3" value="0">.
<input type="text" name="a2" size="3" id="ip2" value="0">.
<input type="text" name="a3" size="3" id="ip3" value="0">.
<input type="text" name="a4" size="3" id="ip4" value="0"></td></tr>
<tr><th>Network mask:</th><td><input type="text" name="m1" id="nm1" size="3" value="0">.
<input type="text" name="m2" size="3" id="nm2" value="0">.
<input type="text" name="m3" size="3" id="nm3" value="0">.
<input type="text" name="m4" size="3" id="nm4" value="0"></td></tr>
<tr><th>Gateway:</th><td><input type="text" name="g1" id="gw1" size="3" value="0">.
<input type="text" name="g2" size="3" id="gw2" value="0">.
<input type="text" name="g3" size="3" id="gw3" value="0">.
<input type="text" name="g4" size="3" id="gw4" value="0"></td></tr>
</table>
</section>
<section>
<input id="btnreset" type="button" class="button" value="Reset" />
<input id="btnapply" type="button" class="button" value="Apply..." />
</section>