1
I have two Hidden fields inside a form they must store the values of a radio button and the selected checkboxes (150 checkboxes), I was able to make the first Hidden field load the value of the selected radio button but I was unable to make the 2nd Hidden store the various checkboxes marked
<form class="navbar-form span7 text-center" role="search" id="search-form" action="../PHP/ValidateForm.php" method="get">
<div class="form-group">
<label class="radio-inline"><input type="radio" name="result_type" value="videos" checked="">Videos</label>
<label class="radio-inline"><input type="radio" name="result_type" value="photos">Photos</label>
<label class="radio-inline"><input type="radio" name="result_type" value="tumblr">Tumblr</label>
</div>
<div class="input-group">
<input class="form-control" type="text" id="search_input" name="search_input" placeholder="Search" />
<div class="input-group-btn">
<button class="btn btn-default" type="submit" name="search_form_submit" value="search">Search</button>
</div>
</div>
<input type="hidden" name="upload-date" value="up-0" />
<input type="hidden" name="from" value="" />
</form>
Radio code Buttons and checkboxes:
<div id="right_sidebar" class="col-md-2"><!-- START Right Sidebar -->
<div class="row">
<h4>Upload Date</h4>
<div class="radio">
<label><input type="radio" name="upload-date" value="up-0" checked="checked">ANYTIME</label>
</div>
<div class="radio">
<label><input type="radio" name="upload-date" value="up-1">Today</label>
</div>
<div class="radio">
<label><input type="radio" name="upload-date" value="up-2">This Week</label>
</div>
<div class="radio">
<label><input type="radio" name="upload-date" value="up-3">This Month</label>
</div>
<h4>From</h4>
<div id="sites-list">
<div class="checkbox">
<label><input type="checkbox" name="site[]" value="site-0" checked="checked">ANYONE</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="site[]" value="site-1">Site</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="site[]" value="site-2">Site</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="site[]" value="site-3">Site</label>
</div>
</div>
</div>
Code that works only for insertion of the value of the radio button to the 1º Hidden
$('input[name=upload-date]').change(function(){
$('#search-form > input[name=upload-date]').val($(this).val());
});
Confirming The 1st Hidden field that stores the radio selection result is working, the 2nd that would store all the checkboxes not.
– Ricardo
You will put only one value, of the 150, in an input?
– Lollipop
yes are 150 options where the user can choose from 0 up to 150 options, they are not self-exclusive so he can choose all
– Ricardo
Then you can stay in the input something like: up-0 up-1 up-2...?
– Lollipop
@Ricardohenrique What is the reason for putting the values in these input’s? When the form is submitted you will receive the input’s
radio
andcheckbox
.– Oeslei
@Rafael input with value=up-0 up-1 up-2 are radio Buttons so there will only be one, Note: the first field Hidden is working
– Ricardo
Hummmm. Then the radio will give a value for the input in the name="upload-date"?? That’s all you want in this step?
– Lollipop
Another thing, it’s not that only one is working, it’s not working at all, because you set a value="up-0", in Hidden. kkk
– Lollipop
@Oeslei want to put the values marked in the checkboxes inside the 2nd hidenn field
– Ricardo
@Rafael when I click on another radio is assigned its value to the Hidden field
– Ricardo
I get it. :)-----
– Lollipop
How many are there? Only these?
– Lollipop
@Rafael will be 4 Radios on the other hand will be 150 chekboxes (has a css applied to have a scroll bar)
– Ricardo
@Ricardohenrique, See if this is the way. I removed Hidden, for conference, and only did the radio: http://jsfiddle.net/voyhzec4/
– Lollipop