1. Problem introduction:
We often need to use ajax in js to send requests to the background. Before that, we need to collect the required Form form parameters. I often solve this problem, which is simple and trouble-free:
// editBasicDataObjectForm is the id of form, and the form of data is name1=val1&name2=val2&name3=val3&.....
var data = $("#editBasicDataObjectForm").serialize();
But once I needed to get field values of radio type in the form separately, I got stuck.
After various reviews, the results were finally obtained.
2. Solution to the problem:
2.1 editBasicDataObjectForm.jsp:
<div calss="baselineType"> <div class="baselineTypeLable"> <label>Baseline type: </albel> </div> <div class="baselineTypeValue"> <input type="radio" name="baselineType" id="baselineType1" value="1"/>Non-baseline<input type="radio" name="baselineType" id="baselineType2" value="2" />Function baseline<input type="radio" name="baselineType" id="baselineType3" value="3" />Assign baseline</div></div>
2.2 BasicDataObjectOperator.js:
var baselineType;var baselineTypeHtmlCol = document.getEementsByName("baselineType");For(var i = 0; I < baselineTypeHtmlCol.length; I ++){If(baselineTypeHtmlCol[i].checked){baselineType = baselineTypeHtmlCol[i].value;}}............... baselineType is the value we need. n_nThe above simple example of obtaining radio-type values in jsp form is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.