On Click I call a javascript where I have captured the radio button value into a variable in the javascript. I then call a render partial passing this radio button variable as local.
I get the error: undefined local variable or method `radio_button_value' for #<#.
Here is my javascript code:
<script>
function render_dir_partial() {
alert('in javascript.');
alert("you chose the option: " + $('form input[type=radio]:checked').val() );
radio_button_value = $('form input[type=radio]:checked').val();
alert ("radio_button_value: " + radio_button_value );
$('#dir_list').html('<%=j render :partial => "dir_list", :locals => { :dir_choice => radio_button_value } %>')
}
</script>
When I run the app, this aleart shows the correct value assigned based on the radio button clicked: alert ("radio_button_value: " + radio_button_value );
If I hard code a value into the code, instead of the variable, everything works fine. Can you please help me figure out the proper syntax to pass the value for radio_button_value to dir_choice?
I did alot of research and everything shows how to read the value when the variable comes from a model defined object.
Here is the hardcoded string that works.
<script>
function render_dir_partial() {
alert('in javascript.');
alert("you chose the option: " + $('form input[type=radio]:checked').val() );
radio_button_value = $('form input[type=radio]:checked').val();
alert ("radio_button_value: " + radio_button_value );
$('#dir_list').html('<%=j render :partial => "dir_list", :locals => { :dir_choice => "watchfolder" } %>')
}
</script>