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 8305069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:59:48+00:00 2026-06-08T17:59:48+00:00

Below is my code: <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <script type="text/javascript"> var flag

  • 0

Below is my code:

<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<script type="text/javascript">
var flag = false;
function test(selObject)
{
    alert("hi");

    var form = document.forms[0];
    alert("form"+form);

    var txtS =  form["city"];
    alert("txt"+txtS);

    var len = txtS.length;
    alert("len"+len);

    for(var i=0; i<len; i++) 
    {
        if (selObject == txtS[i] )
        {
            if(txtS[i].value==txtS[i].options[3].value)
            {
                alert("YOU ARE SELECTING MYSORE CITY");
                flag = true;
            }
            
            if(!txtS[i].options[3].selected && flag)
            {
                var result = confirm("Are you sure you wnat to travel to this city");
                if(result)
                {
                    flag = false;
                }
                else
                {
                    txtS[i].options[txtS[i].options.selectedIndex].selected=false;
                    txtS[i].options[4].selected=true;
                }
            }
        }
    }//end of for loop
}
</script>

<html:form action="/login">
    username:<input type="text" name="username" /></br>
    password:<input type="password" name="password"/></br>
    
    <%
    for(int i = 0; i < 10; i++){
    %>
        <html:select property="city" onchange="javascript:test(this);">
            <html:option value="B">BANGALORE</html:option>
            <html:option value="C">CHENNAI</html:option>
            <html:option value="M">MANGALORE</html:option>
            <html:option value="MR">MYSORE</html:option>
        </html:select></br>
    <%
    }
    %>
    <input type="submit" value="submit"/>
</html:form>

When select-box or combo-box is looped for ten times then I am getting form["city"] length as 10 properly and behaviour of alerts within combox-box is appropriate, but if I have a single-select-box, then instead of giving form["city"] length as 1 it gives it as 4 which is the number of option elements in my dropdown-box.

So my logic doesn’t work here.

How do I make it work for both single as well as multiple combo/select boxes.

Any help would be appreciated.

  • 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-08T17:59:50+00:00Added an answer on June 8, 2026 at 5:59 pm

    Please use a javascript library like jQuery for cross-browser compatibility.

    You can use the following code to determine that only a single select element is present or multiple select elements with the same name are present:

    if (selObject == txtS) {
        alert("Single select");
        // ... your logic for a single combo-box follows after this
    } else {
        // your logic for multiple combo-box follows, like the "for" loop and if-else
    }
    

    When there is only one select box the line var txtS = form["city"]; will return an array of option elements within that select box and when more than one select box with the same name it returns an array of the select boxes.

    Hope this helps.

    Not related to your question, but this logic if(!txtS[i].options[3].selected && flag) will always return false.

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

Sidebar

Related Questions

Below code is working properly now. But if I replace 'text.txt' with ' http://google.com
below code sample does not return the original text after encrypt/decrypt operation and I
The below code works in Firefox but not in Google Chrome: <!DOCTYPE html> <html>
in below code if i replace temp in $(this).text(temp); with something it works and
The below code is writing unreadable characters to the text file: int main ()
Below code is dealing with a TYPE* const pointer. struct D { void Check
Below code is Just for Demo. Html <div> <a href='javascript:' id=foo>Foo</a> </div> <br> <div
Below code not work, but it's work fine for jsf1.2. Now the framework is
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
below code is my databasehandler class i got it from a tutorial. Beside that

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.