Onclick值在html中形成值

时间:2022-01-07 20:29:39

I have 92 value for <input type="hidden" name="location">

我有的92值

  • i can use drop down or other method but it hard to select in drop down
  • 我可以使用下拉或其他方法,但很难在下拉菜单中选择

  • so i displayed all value in rows and colum
  • 所以我在行和列中显示了所有值

how can i make Onclick value to form input????

如何使Onclick值形成输入????

  • and i need to display the selected value
  • 我需要显示所选的值

how can i have hidden form value by click method to form value

如何通过单击方法形成值来隐藏表单值

USA         india     china 
austria     japan     koera

on click to form value

点击以形成价值

2 个解决方案

#1


1  

<span class="country">USA</span>
<span class="country">India</span>

<input type="hidden" name="country" id="country" />

Then jQuery

$('.country').on('click', function() {
    $('#country').val( $(this).text() );
});

If you need to populate the form with a country code instead of a name you could do this:

如果您需要使用国家/地区代码而不是名称填充表单,则可以执行以下操作:

<span class="country" data-code="us">USA</span>
<span class="country" data-code="in">India</span>

<input type="hidden" name="country" id="country" />

Then jQuery

$('.country').on('click', function() {
    $('#country').val( $(this).data('code') );
});

#2


0  

Depends on the HTML.

取决于HTML。

jQuery:

$('select').on('change', function(){
    $(this).closest('form').find('input:hidden').click();
});

#1


1  

<span class="country">USA</span>
<span class="country">India</span>

<input type="hidden" name="country" id="country" />

Then jQuery

$('.country').on('click', function() {
    $('#country').val( $(this).text() );
});

If you need to populate the form with a country code instead of a name you could do this:

如果您需要使用国家/地区代码而不是名称填充表单,则可以执行以下操作:

<span class="country" data-code="us">USA</span>
<span class="country" data-code="in">India</span>

<input type="hidden" name="country" id="country" />

Then jQuery

$('.country').on('click', function() {
    $('#country').val( $(this).data('code') );
});

#2


0  

Depends on the HTML.

取决于HTML。

jQuery:

$('select').on('change', function(){
    $(this).closest('form').find('input:hidden').click();
});