0

In JSP i have like this,

<form:checkbox path="wdays" value="${day.getDaysId()}"/>

And Jquery like

var wday = ($('input:checkbox:checked').val());
$.ajax({
    type: "POST",
    url: contexPath + "/saveShiftAllotment",
    data: "&wday="+ $('input:checkbox:checked').val(),
    success: function(data)
    {       
        alert("Submited to the Medical Department");
    }

and my controller like,

public void
saveShiftAllotment(@RequestParam(@RequestParam(value="wday") int wday)

1 Answer 1

1

In your question, you were not clear if you just want to grab the value, no matter if its checked or not.So i assume you triggering your ajax call when the check box is checked. <form:checkbox path="wdays" value="${day.getDaysId()}"/> will generate something similar to this when rendered.

<input type="checkbox" id="wdays" name="wdays" value="5"/>

So you can grab the value of the checkbox using the id like

to grab the value.

$('#wdays').val()

to check if checked

$('#wdays').is(":checked")

You ajax call will be

$.ajax({
    type: "POST",
    url: contexPath + "/saveShiftAllotment",
    data: {wday:$('#wdays').val()},
    success: function(data)
    {       
        alert("Submited to the Medical Department");
    }

On your spring controller side, do the below.

@RequestMapping(value="/saveShiftAllotment") 
public {your_return_type} saveShiftAllotment(@RequestParam (value="wdays") int wday)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.