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

  • SEARCH
  • Home
  • 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 8449541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:44:13+00:00 2026-06-10T10:44:13+00:00

I have a very critical issue. Below is my jsp code: <html:select property=city name=city

  • 0

I have a very critical issue.

Below is my jsp code:

<html:select property="city"   name="city"  onchange="javascript:checkCity(this);">                             
                        <html:option value="N">NewYork</html:option>                      
                        <html:option value="F">France</html:option>
                        <html:option value="I">Italy</html:option>
                        <html:option value="P">Paris</html:option>
</html:select>

There can be single or multiple html select since my <html:select> is placed in for loop.

Below is my Javascript code:

var citySelected = new Array();
function checkCity(selObject)
{
     var form = document.forms[0];
     var cityObj =  form["city"];
     var len = cityObj.length;
     if(selObject==cityObj)      // if there is single <html:select> selObject is same as city Object.so this logic works fine
     {
        if(cityObj.value==cityObj.options[3].value)
        {
        alert("You have selected Paris City");
        citySelected[0] = true;
        }
        if(!cityObj.options[3].selected && cityObj[0])
        {
        var result = confirm("You have selected cities other than paris");
        if(result)
        {
            citySelected[0] = false;
        }
        else
        {
            cityObj.options[cityObj.options.selectedIndex].selected=false;
            cityObj.options[3].selected=true;
        }
        }
     }
     else{
         for(var i=0; i<len; i++) {  //if there are multiple <html:select> then take length of form object n iterate
                if (selObject == cityObj[i] )  
                {
                    if(cityObj[i].value==cityObj[i].options[3].value) // if 3rd option is selected
                    {
                        alert("You have selected Paris City");
                        citySelected[i] = true;
                    }
                    if(!sctypeObj[i].options[3].selected && citySelected[i]) //if 3rd option is deselected
                    {
                        var result = confirm("You have selected cities other than paris");
                        if(result)
                        {
                            cityObj[i] = false;
                        }
                    else
                    {
                        cityObj[i].options[cityObj[i].options.selectedIndex].selected=false;
                        cityObj[i].options[3].selected=true;
                    }
                    }
                }
         }
     }
}

Below is Javascript which works on jsp onload():

function onload()
{
         var form = document.forms[0];
         var formObj =  form["city"];
         var size=formObj.size;
         var len = formObj.length;

         for(var i=0; i<len; i++) {
         citySelected[i] = false;
         }
         if(size==0){   //if there is seingle <html:select> element
            var cityvalue=formObj.value;
            if(cityvalue=="P")
             {
                 citySelected[0] = true;
             }
         }
         else
         {
            for(var i=0; i<len; i++) {   //if there are multiple <html:select> elements
             var cityvalue=formObj[i].value;
             if(cityvalue=="P")
             {
                 citySelected[i] = true;
             }
            }
         }
}

Here is where am finding problem. Onload if there is single or multiple <html:select> elements the logic works fine.But when there are no <html:select> elements at all in my jsp per say if I have option to delete all dropdowns then my jsp throws Javascript error:

“size is null or not an object”.

How do I resolve this? In onload() function I am differentiating between <html:select> element using size.

if(size==0)
{
   //logic for single <html:select>
}
else
{
  //logic for multiple html select
}

But when there are no <html:select> elements at all in my jsp per say if I have option to delete all dropdowns then my jsp throws Javascript error:

“size is null or not an object”.

How do I resolve this? Any help would be great..

  • 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-06-10T10:44:15+00:00Added an answer on June 10, 2026 at 10:44 am

    An alternate way to determine the number of <select> elements within a form would be to use jQuery‘s selectors like so:

    $('#myForm select').length // returns number of <select> elements in the form
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing Objective-C code with LLVM. I have one file full of very performance-critical
I have an application where performance is very critical issue. The application has 50.000
I have very simple piece of code. The goal is when i input four-digit
I have very very big html page/data. I need to fetch data under h1
Sorry if the question is very naive. I will have to check the below
I'm very new to MSMQ. We have a critical system using MSMQ and it
I have a critical loop in my code with this shape : int myloop(int
I'm currently working on some performance critical code, and I have a particular situation
I have question, maybe it's not critical in programming, but to me it's very
I have a very basic custom edit form, an aspx with code behind. It

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.