I have a form with different options provided by radio buttons. I also have a script which displays different divs with different form inputs.
This script works fine, my problem is that I have a “previous” link where a user can go one step back and edit already entered data and that I can’t force the different options with the checked attribute to the radio button. It has to be clicked, which make sense because my script uses the .click event.
But how can I say something like: “If $_SESSION[‘unemployed’] == ‘yes’ then echo ‘checked’” and it shows the right option.
I hope I explained myself correctly otherwise fell free to ask.
Please see the code live here http://jsfiddle.net/GEFMX/1/ and my question is if one or more or the checkboxes default is “checked”.
The Javascript I’m using looks like this:
<script type="text/javascript">
$(function() {
$("input[name$='step2_student']").click(function() {
var diffoptions = $(this).val();
$("div.studerende_janej").hide();
$("#studerende" + diffoptions).show();
});
$("input[name$='step2_otheredu']").click(function() {
var diffoptions = $(this).val();
$("div.othereducation_janej").hide();
$("#othereducation" + diffoptions).show();
});
$("input[name$='step2_haveeducation']").click(function() {
var diffoptions = $(this).val();
$("div.haveeducation_janej").hide();
$("#haveeducation" + diffoptions).show();
});
});
</script>
Sincere
– Mestika
You can add some code to your page load to trigger a ‘click’ for all radios that are checked. i.e. something like: