0

Hi I am new in javascript Below is my jsp code and on click of submit button I want to force a user to select at least one radio box/record. how do I perform this task.

Thanks in advance.

<body>
<form:form id="myForm" action="actionValue" method="GET">
    <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for Excel Names.." title="Type in a name">

    <table id="myTable">
      <tr class="header">

        <th>Select</th>
        <th>Excle SrNum</th>
        <th>Excle Name</th>
        <th>Uploded By</th>
        <th>UplodedBy ID</th>
        <th>Uplod Date and Time</th>
        <th>xml Genrated ?</th>
        <th>xml Genration Date and Time</th>
        <th>Action</th>
      </tr>
          <c:forEach items="${UploadFileModel}" var="UploadFileModel">
            <tr>
                <td><input type="radio" name="select"  value= "${UploadFileModel.srNum}" id="radioButton"/></td>
                <td>${UploadFileModel.excleSrNum}</td>
                <td>${UploadFileModel.fileName}</td>
                <td>${UploadFileModel.uplodedByName}</td>
                <td>${UploadFileModel.uplodedByNum}</td>
                <td><fmt:formatDate value="${UploadFileModel.uplodeDateTime.time}"  type="date"  pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>${UploadFileModel.xmlGenrated}</td>
                <td><fmt:formatDate value="${UploadFileModel.xmlGenrationDateTime}" type="date"  pattern="yyyy-MM-dd HH:mm:ss"/></td> 
                <td><input type = "submit"  name="GenrateXML"    value="Genrate XML"   id="xmlButton"   />
                    <input type = "submit"  name="DeleteRecord"  value="Delete Record" id="Delete Button"/>
                </td>
           </tr>
         </c:forEach>
   </table> 

   <!-- ********* Below code showing error message from controller if any***********..... -->                
                <form:errors path="*" />
                   <c:if test="${not empty message}">
                   <h4 style="font-style: italic; color: red;">${message}</h4>
                   </c:if>  
  <!-- ********* Above code showing error message from controller if any************..... --> 
   </form:form>
</body>
Pankaj Dagar
  • 87
  • 10
  • 1
    Possible duplicate of [JQuery Require Checkbox and Radio Button before submit](https://stackoverflow.com/questions/849155/jquery-require-checkbox-and-radio-button-before-submit) – Turnip Feb 28 '18 at 12:09

3 Answers3

2

You can use required like this:

<input type="radio" name="select" value="${UploadFileModel.srNum}"id="radioButton" required/>

more info here: HTML input required Attribute | w3schools

zb22
  • 3,126
  • 3
  • 19
  • 34
0

For javascript use below code if ($("input[type=radio]:checked").length > 0) { // Do your stuff here } Check the radio button length and do the operation.

Gopal
  • 787
  • 3
  • 13
  • 19
0

You can keep the names of all the radio buttons same, that is; creating a radio button group and then add an attribute required in the radio tags

Refer to the link below too.

How to make radio inputs required?