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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:50:00+00:00 2026-05-30T19:50:00+00:00

I have two buttons. Both buttons have two attributes – data-from and data-to. When

  • 0

I have two buttons. Both buttons have two attributes – “data-from“ and “data-to“. When any of the button is clicked, these attribute values need to be passed on to a hidden field and the form need to be submitted (POST). Before submitting, I need to alert the attribute values from the hidden fields also. How do I do that?

Note: The following code is written using ASP.NET Webforms.

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"> </script>

<script type="text/javascript">

    $(document).ready(function () 
    {
        $('#mainDiv input[type="button"]').on('click', function () 
        {
            alert('HAi');
            $('#from').val($(this).attr('data-from'));
            $('#to').val($(this).attr('data-to'));

            //alert($('#from').val);
            //alert($('#to').val);

            $('this').closest('form').submit(); 
        });
    });
</script>
</head>
<body>
<div id="mainDiv">
<form id="form1" runat="server">
<div>
    <input type="button" 
              value="Show March Programs" 
              data-from="01-03-2012" 
              data-to="31-03-2012" />

    <input type="button" 
               value="Show 2012 Programs" 
               data-from="01-01-2012" 
               data-to="31-12-2012" />

        <input type="hidden" id="from" value="1" />

        <input type="hidden" id="to" value="2" />
</div>
</form>
</div>
</body>
</html>

READING:

  1. How do i Pass the Value To hidden using attr in jquery
  • 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-30T19:50:01+00:00Added an answer on May 30, 2026 at 7:50 pm

    Your code is almost there. It was failing on the submit function which you can use either the generic $(‘form’) (in case you have only one form in your page or you can change it to $(‘#form1’). You need to change also the action and method in your form.

    Now, I see that you are using non-standard attributes to store values, this ‘works’ but is not syntactically correct. You might need to change it if you want to pass the validation.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"> </script>
    <script type="text/javascript">
        $(document).ready(function () 
        {
            $('#mainDiv input[type="button"]').on('click', function () 
            {
                alert('HAi');
                $('#from').val($(this).attr('data-from'));
                $('#to').val($(this).attr('data-to'));
    
                alert($('#from').val());
                alert($('#to').val());
    
                $('form').submit(); 
            });
        });
    </script>
    </head>
    
    <body>
    <div id="mainDiv">
      <form id="form1" runat="server" action="index.html">
        <div>
          <input type="button" 
                  value="Show March Programs" 
                  data-from="01-03-2012" 
                  data-to="31-03-2012" />
          <input type="button" 
                   value="Show 2012 Programs" 
                   data-from="01-01-2012" 
                   data-to="31-12-2012" />
          <input type="hidden" id="from" value="1" />
          <input type="hidden" id="to" value="2" />
        </div>
      </form>
    </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Everybody.. How to set animation on button click ? I have two buttons, both
I have two elements (a button and an anchor tag) both with a dynamical
I have two buttons with the same ID: <button type=submit onclick=//do something id=theID>button 1</button>
I have two radio buttons each with a unique ID. When one is clicked,
I have two buttons, one of class button white and another one of class
I have two radio buttons both set as async triggers for an update panel
Simply scenario -- I have two buttons both of which call the same controller/action.
Alright, I have a simple java applet with two buttons and a screen. Both
Ok, i have two buttons in linear layout: <LinearLayout android:id=@+id/linearLayout1 android:layout_height=wrap_content android:layout_width=fill_parent> <Button android:id=@+id/aktiviraj_paket
So, I'm developing an app and need to have two buttons pressed at the

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.