The value of a array has to become an input field

2019-06-02 11:24发布

this is my array

        $m3 = array
          (
           '2' => '2',
           '4' => '4',
           '6' => '6',
           '9' => '9',
           '14' => '14',
           '18' => '18',
           '20' => '20',
           'other' => 'other'

            );

How do I get 'other' to change in what I put in the inputfield 'other_interest'?

   <?=$form->input('Car/m3', array('name' => "other_interest", 'style' =>        "display:none", 'class' => 'inputText', 'label' => false));?>

The jQuery shows the inputfield when I choose other

  <script>
 jQuery(document).ready(function() {
    jQuery("#CarM3").change(function() {
        if (jQuery(this).val() === 'other'){ 
            jQuery('input[name=other_interest]').show();   
         } else {
            jQuery('input[name=other_interest]').hide(); 
        }
     });
});
</script>

1条回答
SAY GOODBYE
2楼-- · 2019-06-02 11:56

What I understand from your question is that, you want "other" to be displayed in the inputfield : "other_interest".

  <script>
  jQuery(document).ready(function() {
  jQuery("#CarM3").change(function() {
    if (jQuery(this).val() === 'other'){ 
        jQuery('input[name=other_interest]').show();   
        //in the above line, you are just displaying the inputfield
        jQuery('input[name=other_interest]').val("other") //adding this line should do the trick for you!

     } else {
        jQuery('input[name=other_interest]').hide(); 
    }
  });
 });

查看更多
登录 后发表回答