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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:36:38+00:00 2026-05-29T15:36:38+00:00

I am new to jquery and have been experimenting with it for the last

  • 0

I am new to jquery and have been experimenting with it for the last couple of days and have been successful with it until I got to this point. I am working on an edit users page and I have problem choosing the right role from a list that is already populated from the datbase.
//this is the select user drop down

  <select id="ddlUsers" name="ddlUsers" >
    <option value="0">--Select User--</option>
    <%for(Usertable user:usertableModel.getAllUsertables()){ %>
      <option id="<%=user.getUserid() %>" value="<%=user.getUserid() %>" 
          onclick= "showUserRole('<%=user.getRole().getRoleid() %>' )">     <%=user.getLastname() %> , <%=user.getFirstname() %>
   </option>
   <%} %>

// this is the select option for which I want to select the right role of the user selected from the first drop down.

<select name="ddlRoles">
  <%for(Role r:roleModel.getAllRoles()){ %>
    <option value="<%=r.getRoleid() %>"><%=r.getRolename() %></option>
  <%} %>
</select> 

//here is the jquery I tried to use

function showUserRole(role){
   $('#ddlRoles').each(function(){
      if($('option', this).val() == role){
    $('option', this).attr("selected","selected");
      }
  });
 }

but obviously its not working…. so any help is appreciated… thank you

  • 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-29T15:36:39+00:00Added an answer on May 29, 2026 at 3:36 pm

    ddlRoles is the value of name attribute you cant use it as id selector. try this

    if <select name="ddlRoles">

    then

    function showuserRole(role){
        $('select[name="ddlRoles"]').val(role);
    }
    

    else change it as <select id="ddlRoles">

    then

    function showuserRole(role){
        $('select#ddlRoles').val(role);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey people I'm new at jquery and i have been trying to figure this
Alright have been working to switch to jQuery 1.7's new and improved .on() function
Im very new to all coding including jquery. I though this would have been
I am very new to javascript and ajax/jquery and have been working on trying
Ok guys im new to jquery and have been making considerable progress but this
I'm completely new to jQuery/javascript and have been beating my head against this simple
New to SO and javascript. I have been playing with JQuery for a couple
I'm new to jQuery and have noticed someone go: var $this = $(this); Why
I am fairly new to JQuery API. I have been using mouseover, but I
I am new to Ajax and have been following a tutorial from JQuery.com. I

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.