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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:11:11+00:00 2026-06-18T06:11:11+00:00

Im learning javascript and I have this function: function getRadioCity() { for (index=0; index

  • 0

Im learning javascript and I have this function:

   function getRadioCity() {
    for (index=0; index < document.form_data2.ciudades.length; index++) {
        if (document.form_data2.ciudades[index].checked) {
            var radioValue =form_data2.ciudades[index].value;
             return parseInt(radioValue);
        }
    }
}

The function works fine but what if i have a select form instead radio?

For example:

<div id="content" style="display:none;">
<form name="form_data2" id="form_data2"> <br>

<select name="ciudades" id="ciudades">
<option value="33">Armenia</option>
<option value="34">Cartagena</option>
</select>
 <input value="Enviar" id="btn_enviar" href="javascript:toggle() </input> <br /> <br />         <label id=" mensaje2="" type="button"> </form>
  <div id="resultado2"></div>
   </div>

Thanks in advance for your help. Ill tried the same thing but doenst work..

edit:

I tried to make something like this:

      $(document).ready(function(){
 $('#btn_enviar').click(function(){

  if( validaSelect( 'ciudades','ciudades' ) == false) return false;


    $.ajax({
        type:'POST',
        url :'upload2.php',
        data: $('#form_data2').serialize(),
        beforeSend : function(){
            $('#mensaje2').html('Enviando datos...');
        },
        success: function (data){
                $('#mensaje2').html('Datos enviados correctamente.');
                $('#resultado2').html(data);    
        },
        complete: function(){
             $('#form_data2').slideUp();
             $('#resultado2').slideDown();
              $('#content2').show();
              $('#flecha2').show();
             var num2 = getRadioCity();
        if (num2==1){
             $('#armenia').show();

        } 
         if (num2==2){
             $('#cartagena').show();
             alert("cartagena");

        } 



        }
    });

}); 


       });

basically get the value depending on the select and display a div or other

  • 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-18T06:11:13+00:00Added an answer on June 18, 2026 at 6:11 am

    You can access the value of select using selectedIndex.

    document.getElementById("ciudades").onchange = function() {
        alert(this.selectedIndex);
    }
    

    Each option has its own number identifying itself. In the case of a select element, the first option has a selectedIndex of 0 and the second has a selectedIndex of 1 and so on. From this you can tell which option is selected.

    See DEMO.

    Try this:

    var num2 = document.getElementById("ciudades").selectedIndex;
    if (num2==0){
         $('#armenia').show();
    } 
    if (num2==1){
         $('#cartagena').show();
         alert("cartagena");
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this javascript function myFunction(source) { window.open(source, Title, 'width=400, height=400'); } and in
Hello fellow programmers, I have taken up learning JavaScript. This syntax is pure sorcery,
This might be a simple one for you guys, im learning Javascript and have
Sorry if this sounds silly, I am still learning server-side Javascript. I have this
I'm learning jQuery/javascript and have a rather basic question. Why doesn't this work? Thanks
I am learning Javascript and I have read functions are first class objects and
I have a simple request(still learning javascript). I have a title div and 3
I have looked on Google, and everywhere in the forums. Just learning JavaScript, so
I am making a small calculator (just for JavaScript learning) and I have two
I have been learning the Definitive Guide of JavaScript.i got a question about the

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.