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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:20:14+00:00 2026-06-12T14:20:14+00:00

I have a <div class=foo>Foo</div> and I have two input fields: <input type=submit class=text_field

  • 0

I have a <div class="foo">Foo</div> and I have two input fields:

  1. <input type="submit" class="text_field" name="input_one" value="">
    and
  2. <input type="submit" class="text_field" name="input_two" value="">

I would like to be able to click <div>Foo</div> and populate field #1 with the value Foo and field #2 with value Bar. (Extrapolate upon this idea to incorporate many different divs and thus, many different value combinations.) How best can I do this using jQuery?

So far I have no trouble doing something like:

jQuery(function () {
$('div.foo').click(function (e) {

    var foo = $(this).text();

    $("input.text_field").val(foo);
});
});​

This works for clicking the div and populating one text field with the text value between the tags, i.e., “Foo”. This is a good start and all…but since I am new to this, I was wondering how might I best go about populating the two different text fields with two different said values “Foo” and “Bar”. Is there a way to set a name="Bar" or something to this effect on the div, and then access that name value to insert into the second text field input_two? Thoughts, comments, considerations 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-06-12T14:20:16+00:00Added an answer on June 12, 2026 at 2:20 pm

    it’s a weird question, can you explain what you NEED to do? I mean, you posted what you want to do, but why do you want to do that? it’s not clear what are Bar and Foo, are those predefined values for each submit? does the value depend on the div (let’s say you have more than one div and you need to populate the inputs depending on which div was clicked)

    you can put any attribute to any tag that you need and access them using $([selector]).attr(‘attr_name’) to get the value, html5 defines some “data-” attributes to store thing like that http://html5doctor.com/html5-custom-data-attributes/

    EDIT:
    you can have something like

    <div class='clickeable' data-input1='foo' data-input2='bar'></div>
    <div class='clickeable' data-input1='baz' data-input2='xxx'></div>
    

    and the js

    $('.clickeable').click(function(){
      obj = $(this);
      $('input[name=input_1]').val(obj.attr('data-input1'));
      $('input[name=input_2]').val(obj.attr('data-input2'));
    })
    

    then the js is generic and you can add as many divs as you want whit any values

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function submitValue () { var content = $('input[name=foo]').val(); $('.teamcolumn').html(content); } $('#team').submit(submitValue()); I have also
I have many DIV with the same class name, let save wmplayer. I want
I have a class of div MyClass I want to hook up to two
I have a HTML document (string) which contains a div with the class foo:
I have the following HTML: <div> <p>foo</p> <p class='foo'>foo</p> <p class='foo'>foo</p> <p>bar</p> </div> How
I have the following HTML: <DIV class=foo bar></DIV> I'm trying to create a CSS
Let's say I have the following. <div class=foo> <div> some text <div class=bar> </div>
I currently have the following markup: <div class=foo> <ul class=bar> <li class=a></li> <li class=b></li>
I have this markup: <div id=container> <h1>Heading</h1> <p>Some text</p> <div class=foo>Some stuff</div> <div class=foo>Some
I have a structure; <p class = foo>sometext</p> <div class = foo> <p class

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.