How do i get the value of a checkbox and put it in a variable for insertion in DB?
$request->param(cb)
is not getting the value
the checkbox is in a mason2 component(.mc) and the value of the checkbox will be pass to another component. so i have to find a way to get the value when it is submitted
here is the code
<input type="checkbox" name="cb" value="" onclick="$(this).attr('value', this.checked ? 1 : 0)">
For tasks like this, the combination of WWW::Mechanize and HTML::TokeParser is your friend. The former helps you navigate by clicking buttons, links, etc. and the latter slices and dices the HTML.
In this case, you simply navigate to the page, scan the data for 'input' tags (i.e. a 'checkbox' is a type of 'input') and then test each input to see whether the 'name' attribute matches the one you're after. Once you've found the correct 'input' tag, then you just grab the value of the 'checked' attribute, which you can then use a you like.
For example:
In this example, the "navigation" part is trivial and you could probably get by without WWW::Mechanize. However, in some cases, you need to submit input, click buttons, use links, etc. so it often comes in handy.