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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:02:09+00:00 2026-06-02T14:02:09+00:00

Upon clicking a button with dynamic id, I want to put dst.district into a

  • 0

Upon clicking a button with dynamic id, I want to put dst.district into a textbox with id district.
I have written following code, but it’s currently not working.

<input name="" type="text" class="dist1" id="district">
   <% @districts.each do |dst|%>                         
       <div id="dist_<%= dst.id%>" class="districtname"><%= dst.district %></div>                        
       <input id="select_<%= dst.id%>" type="button" value="Select" class="gbutton" />
   <script type="text/javascript">
    $("#select_<%= dst.id %>").click({
                $("#district").val("<%= dst.district %>");
    });
   </script>                        
   <%end%>  

Thank you in advance.

  • 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-02T14:02:25+00:00Added an answer on June 2, 2026 at 2:02 pm

    Just follow this code:

    <input name="" type="text" class="dist1" id="district">
    <% @districts.each do |dst|%>
      <li>                    
       <div class="districtname"><%= dst.district %></div>                        
           <input name="select" id="select_<%= dst.id%>" type="button" value="Select" class="gbutton" />
      </li>                    
    <%end%>
    

    and

    $(".gbutton").click(function(){
            var getID = this.id.split("_");
            console.log(getID[1]);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 16 <li> items. Upon clicking a button, I run the following code
I have div1 and div2, upon clicking copy button I want the text in
I have a WPF app, upon clicking a button, the app goes into a
I stumbled upon Jtalk here http://nicolaspetton.github.com/jtalk/index.html#download but when clicking on download I have 404
I have 4 radio buttons in one group. Upon clicking the radio button the
In my main page, I have to call a colorbox upon clicking a button.
I have the following jQuery code: $('.button').click(function(e) { e.preventDefault(); var id = $(this).attr('id'); var
I have an aspx page on which I have 2 static jquery tabs.Upon clicking
If I define the following template inside DetailsView , then upon clicking an Update
There's a form with three checkboxes and a button. Upon clicking on the button

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.