0

This is a part of my HTML form:

<form name = 'myform'>
  <input type='button' name='mybutton' value='Activate'>
  <input type='hidden' name='myhidden' value='elementvalue'>

I want to send the value of the hidden element to the server when the user clicks the 'Activate' button by using Ajax. Here is a snippet that works, but I need to change this part:

$("input[name=choice1]").val(this.value);

in order to select my hidden element value and I don't know how.

At this moment I'm learning Python, Flask/Jinja2 and HTML/CSS at the same time, so diving into jQuery as well is just too much right now.

Thank you for your efforts.

Community
  • 1
  • 1
Lisosia
  • 3
  • 1
  • @dda, I noticed you went through some effort to clean up my post. Not that I'm offended or anything, but just to learn: is there some meaning I should derive from that? Did I break some unwritten rule? – Lisosia Jul 25 '13 at 19:32

2 Answers2

1

try

$("input[type=hidden]")

it will select all the hidden elements from your form.

Anand Shah
  • 611
  • 7
  • 14
0
$("input[name=myhidden]").val(this.value);

just modify the selector. see the docs http://api.jquery.com/category/selectors/

Brad
  • 6,106
  • 4
  • 31
  • 43
  • This led to a working solution after some experimenting. I still don't fully understand why I can pass variables to the server-side function using any name for the 'data' element of the jQuery post-method, but that's for another time. – Lisosia Jul 25 '13 at 19:26