SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast kong's Avatar
    Join Date
    Jan 2008
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Radio button - making text appear and disappear

    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

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kong View Post
    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.
    What text? Post the html you are referring to.

    Also, why are you using jquery?

    You'd be better off learning the basics of javascript first before playing with jquery, which is just prewritten javascript functions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •