[Solved] Set html checkbox and input tag from javascript using a variabe [closed]


You can do something like this:

var data = {
  "user_id": "4BtIrO4vgJUZG3wUxDjihnKbYvw2",
  "travel_mode": "plane",
  "travel_with": ["family", "couple"],
  "travel_preferences": "national",
  "budget": "321"
}

$("input[type=radio][value=" + data["travel_mode"] + "]").prop("checked",true)

demo

var data = {
  "user_id": "4BtIrO4vgJUZG3wUxDjihnKbYvw2",
  "travel_mode": "plane",
  "travel_with": ["family", "couple"],
  "travel_preferences": "national",
  "budget": "321"
}

$("input[type=radio][value=" + data["travel_mode"] + "]").prop("checked",true)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="traveltype" onclick=" " type="radio" name="options" value="car" id="radio1"></input>
<input class="traveltype" onclick=" " type="radio" name="options" value="plane" id="radio2"></input>
<input class="traveltype" onclick=" " type="radio" name="options" value="train" id="radio3"></input>
<input class="traveltype" onclick=" " type="radio" name="options" value="walk" id="radio4"> </input>

solved Set html checkbox and input tag from javascript using a variabe [closed]