Javascript checkbox onChange

后端 未结 10 1195
孤街浪徒
孤街浪徒 2020-11-28 06:00

I have a checkbox in a form and I\'d like it to work according to following scenario:

  • if someone checks it, the value of a textfield (totalCost)
10条回答
  •  感情败类
    2020-11-28 06:43

    I know this seems like noob answer but I'm putting it here so that it can help others in the future.

    Suppose you are building a table with a foreach loop. And at the same time adding checkboxes at the end.

    
    
     
     
     
     
       
    >

    You place a button below the table with a hidden input:

    Submit Changes

    You can write your script like so:

    
    

    The ids of your checkboxes will be submitted as a string "1,2" within the result variable. You can then break it up at the controller level however you want.

提交回复
热议问题