Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JavaScript - Pass selected drop down list value to method

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaScript - Pass selected drop down list value to method

    This may be a simple thing, but I am trying to capture the selected value from a drop down list on an JSP page and use the selected value as an argument to a method. I am able to use the onchange event in the select tag to call a java script function and capture the value but I am not sure how to send the value to the method. I think there is a way to do this via an ajax based call but I am not sure how to accomplish this. To be clear this code runs but I don't know how to pass the value to a method on the JSP page. Here is a sample of the test code I am using. Thank you.

    <script>
    function getSelected()
    {
    var selectedSource = document.getElementById("myselect").value;
    console.log(selectedSource);
    }
    </script>

    <select name="myselect" id="myselect" onchange="getSelected();">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
    </select>

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JavaScript - Pass selected drop down list value to method

    Javascript is not the same as java. Look for a javascript forum for your questions.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to Pass the value of selected radio button from one jsp to another
    By Anonymous6 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 5th, 2018, 08:54 AM
  2. getting data from arraylist into a drop down list
    By nallamchaitanya in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2013, 04:42 AM
  3. Replies: 0
    Last Post: February 12th, 2011, 07:44 PM
  4. Using getElementById() to get values from drop down list
    By oric1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2011, 06:52 PM