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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:45:07+00:00 2026-06-10T20:45:07+00:00

I have some javascript on a view that makes an ajax call to my

  • 0

I have some javascript on a view that makes an ajax call to my controller. I’m looping through the data and i’m building a table.
What I need to do is for each item in the table, make it a hyperlink, and then when the user clicks on any of the links, i want to populate a textbox with the value of the link.

So far, my code to loop through the json data and build my table works. Here’s a snippet of the code:

            htmlstring = htmlstring + "<th>VlanId</th><th>Name</th>";
    for(i = 0; i < returnDataFromController.length; i++) {
        //alert(returnDataFromController[i].VlanId);
        htmlstring = htmlstring +  "<tr><td><a href=''>"+returnDataFromController[i].VlanId+"</a></td><td>"+ returnDataFromController[i].Name+"</td></tr>";          
    }
    submitFormHTML = "<input type='text' id='newVlanID' style='width:5em;height:1.5em'/>&nbsp;&nbsp;<button class='btn' id='saveVlan' style='width:10em;height:2em'>Reassign Vlan</button>";
    $('#clientajaxcontainer').html(htmlstring);
    $('#newvlanform').html(submitFormHTML);

In order to accomplish what I want to do, do I need to give each tag a unique name or can i just assign it to a class? It’d be nice if I could assign every a tag a certain class – eg) classX… and then write a jquery handler for click event of tags of type classX.
Is this possible? Thanks for taking the time to read this post.

Edit:

I am using jquery version 1.8. In addition the code above, I’ve added some more javascript to try to autopopulate the textbox based on a click event:

 $('clientajaxcontainer').on("click", "td:first-child a", function(ev) {
  ev.preventDefault();
  $('#newVlanID').val($(this).text());
  });

If I understand correctly, the ev.preventDefault() should stop the browser from redirecting me to another page. But that doesn’t seem to be working. When I click on any of the hyperlinks, it reloads the current page.

  • 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-10T20:45:08+00:00Added an answer on June 10, 2026 at 8:45 pm

    Use the delegate version of .on() and add a click handler to your ajax container.

    $("#clientajaxcontainer").on("click", "td:first-child a", function(ev) {
        ev.preventDefault();
    
        $("#newVlanID").val($(this).text());
    });
    

    Example from another question but it is really close to this solution just without the link tag 🙂

    Edit
    For jQuery versions below 1.7 you can use .delegate() instead

    $("#clientajaxcontainer").delegate("td:first-child a", "click", function(ev) {
        ev.preventDefault();
    
        $("#newVlanID").val($(this).text());
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that contains a javascript function that i need to init/call
I have some javascript that I am using for some audio on my website:
I have some javascript that goes out and fetches a javascript class on another
i have some javascript roll over code that works fine in firefox but when
I have some Javascript code that will programmatically register an COM interop assembly by
I have some JavaScript code that works in IE containing the following: myElement.innerText =
I have some javascript code that creates an img tag with a mouseover callback,
I'm building an interactive javascript application that needs to make some SOAP requests to
I have an Ubuntu server with a LAMP stack. I have some javascript that
I have some javascript where I append an option to a select: var myuniqueddl

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.