2015-05-28 09:29
浏览 31


I have a bike
I have a car

I know when the form is submitted the value will be vehicle=Bike&vehicle=Car if both are ticked

Is there a way to make the value to be vehicle=Bike,Car

Put them into one variable then separated in a comma

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongyu3712 2015-05-28 09:40

    Since you are using POST and multiple check boxes, set the name of each check box like this:

    <input type="checkbox" name="vehicle[]" value="Bike">
    <input type="checkbox" name="vehicle[]" value="Car">

    Then when your form is submitted you will receive an array of all the checked boxes and their values in the array:


    Now if both boxes are checked you can retrieve the values in a foreach loop:

    foreach($_POST['vehicle'] as $type){
       echo "Type = ".$type;

    With this you will get an output of

    Type = Bike
    Type = Car
    打赏 评论
  • donglu9978 2015-05-28 09:43

    Try this one,

    <input type="hidden" name="vechiclesStr" id="vechiclesStr">
    //on submitting,
    document.getElementById("vechiclesStr").value = document.formname.vechicle.join();
    打赏 评论

相关推荐 更多相似问题