Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:36:44+00:00 2026-05-17T22:36:44+00:00

I have written a script that checks a set of radiobuttons to be checked.

  • 0

I have written a script that checks a set of radiobuttons to be checked. But due to different possibilities different radiobuttons will show. Is there a way to suppress JavaScript errors when it pops undefined/getElementById is null? Something like the @-char does in PHP?

Update:

A bit more background info. I’ve made a website where users can submit images and another party for whom the images are can select their top 3 of the images. So each image has three radiobuttons. The difficulty here lies in the fact that the radiobuttons must be controlled dimensional (horizontal and vertical), because a submitted image may only be at place 1, 2 or 3. This is my working code. But adding many if(!var == undefined) doesn’t make the code prettier. Therefor I’m wondering if there is something like @suppressMe is possible?

function HandleRadioButtons(id, type, idString, img)
{
    var idArray = idString.split("|");  
    var place1  = document.getElementById("G_" + id);
    var place2  = document.getElementById("S_" + id);
    var place3  = document.getElementById("B_" + id);
    var img1    = document.getElementById("Winner1");
    var img2    = document.getElementById("Winner2");
    var img3    = document.getElementById("Winner3");    

    switch(type)
    {
        case "G" :
            place2.checked = false;
            place2.disabled = true;
            place3.checked = false;
            place3.disabled = true;
            img1.style.background = 'url(' + img + ') no-repeat center center #FFF';
            break;
        case "S" :
            place1.checked = false;
            place1.disabled = true;
            place3.checked = false;
            place3.disabled = true;
            img2.style.background = 'url(' + img + ') no-repeat center center #FFF';
            break;
        case "B" :
            place1.checked = false;
            place1.disabled = true;
            place2.checked = false;
            place2.disabled = true;
            img3.style.background = 'url(' + img + ') no-repeat center center #FFF';
            break;
    }     

    var current1, current2, current3 = "";

    for(i = 0; i < idArray.length - 1; i++)
    {
        var place1 = document.getElementById("G_" + idArray[i]);
        var place2 = document.getElementById("S_" + idArray[i]);
        var place3 = document.getElementById("B_" + idArray[i]);

        if(place1.checked == true)
        {
            var current1 = idArray[i];            
        }

        if(place2.checked == true)
        {
            var current2 = idArray[i];            
        }

        if(place3.checked == true)
        {
            var current3 = idArray[i];            
        }
    }

    for(i = 0; i < idArray.length - 1; i++)
    {        
        var place1 = document.getElementById("G_" + idArray[i]);
        var place2 = document.getElementById("S_" + idArray[i]);
        var place3 = document.getElementById("B_" + idArray[i]);

        if(idArray[i] != id && idArray[i] != current1 && idArray[i] != current2 && idArray[i] != current3)
        {
            switch(type)
            {
                case "G" :
                    place1.disabled = false;
                    place2.disabled = false;
                    place3.disabled = false;
                    break;
                case "S" :
                    place1.disabled = false;
                    place2.disabled = false;
                    place3.disabled = false;
                    break;
                case "B" :
                    place1.disabled = false;
                    place2.disabled = false;
                    place3.disabled = false;
                    break;
            }
        }
    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:36:44+00:00Added an answer on May 17, 2026 at 10:36 pm

    You can easily test for a null or undefined value in JavaScript, as both these values are falsy:

    var element = document.getElementById('some-id');
    if (element) {
       element.value = 'Hello';
    }
    

    You could also consider using a try/catch block:

    try {
       var element = document.getElementById('some-id');
       element.value = 'Hello';
    
       // ... the rest of your code here.
    }
    catch (e) {
       if (!(e instanceof TypeError)) {
          // The exception is not a TypeError, so throw it again.
          throw e;
       }
    }
    

    However be careful that the above will suppress all the TypeError exceptions and that might make your code more difficult to debug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a bash script that gets three paths based on input parameters
I am trying to download some files. I have written a php script that
I have written a small jquery application that allows a person to slide a
I have written a script which is fetching data from database. Now I want
I've written some code to display my favorites in IE8 but for an unknown
I have a folder and it's name is v3 . There are jsp files
Is there a Perl module which can test the CGI output of another program?
I have about 500 HDF5 files each of about 1.5 GB. Each of the
I have mysql tables with utf8 encoding. The Data Backend and phpmyadmin are also
In our database tables we keep a number of counting columns to help reduce

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.