Hi i am new to Javascript
I have 2 different types of radio buttons. if i click on one i want to make the text disappear.
How can i combine them in one function.
example1
//radio button 1
$(document).ready(function() {
setTemplateVersion();
$(“input[name=generator_version]”).click(function() {
setTemplateVersion();
});
});
function setTemplateVersion() {
if($(“input[name=generator_version]:checked”).val() == ‘1’) {
$(“#preview_image”).attr(‘src’,‘gfx/preview_standard.png’);
$(".topimage").hide();
$(".topimage2").hide();
$(".toppbilde_bg").hide();
$(".toppbilde").hide();
$(".logo_text").hide();
} else if($("input[name=generator_version]:checked").val() == '2') {
$("#preview_image").attr('src','gfx/preview_ny.png');
$(".topimage").show();
$(".topimage2").show();
$(".logo_text").show();
$(".logo_bg").show();
$(".toppbilde").show();
}
}
//radio buttone 2
$(document).ready(function() {
$(“input[name=toppbilde_type]”).click(setToppbilde);
setToppbilde();
});
function setToppbilde() {
var val = $("input[name=toppbilde_type]:checked").val();
if (val == 'BIG') {
$(".toppbilde_bg").show();
$(".toppbilde").hide();
} else if (val == 'SMALL') {
$(".toppbilde").show();
$(".toppbilde_bg").hide();
} else {
$(".toppbilde").hide();
$(".toppbilde_bg").hide();
}
}
// i want to combine the two like this. But its not working
// radio button 1 and radio button 2
$(document).ready(function() {
$(“input[name=toppbilde_type]”).click(setTest);
$(“input[name=generator_version]”).click(setTest);
setTest();
});
function setTest() {
var val = $("input[name=toppbilde_type]:checked").val();
var val2 = $("input[name=generator_version]:checked").val2();
if (val == 'BIG' && val2 == '2') {
$(".toppbilde_bg").show();
$(".toppbilde").hide();
} else if (val == 'SMALL' && val2 == '2') {
$(".toppbilde").show();
$(".toppbilde_bg").hide();
} else {
$(".toppbilde").hide();
$(".toppbilde_bg").hide();
}
}
Any help would be greatly appreciated
Kind regards