I want to make a large box into a form element. When the box is selected it should be submitted to the form. How do I change a div into a form element?
I want the border to change colors when the div is selected. This is what I have so far: <form action="" method="get"> <a href="#" class="tog"><div id="left-box" class="col-sm-4 box"><input type="hidden" name="hid" value="val01" /></div></a> <a href="#" class="tog"><div id="center-box" class="col-sm-4 box"><input type="hidden" name="hid" value="val02" /></div></a> <a href="#" class="tog"><div id="right-box" class="col-sm-4 box"><input type="hidden" name="hid" value="val03" /></div> </a> <div class="clearfix"></div> <button type="button" class="btn btn-success">Continue</button></div> </form> <script> $(document).ready(function(){ $(".tog").click(function(){ var atag = $(this); var hiddenInput = atag.find('input[type=hidden]'); atag.removeClass("box").addClass("select-box"); //alert(hiddenInput.val()); }); }); </script> <style> .box { height: 400px; width: 256px; border-radius: 10px; border: thin solid #86939e; } .select-box { height: 400px; width: 256px; border-radius: 10px; border: thin solid #7dc855; }</style> Code (markup):
Have a hidden form element that is given the appropriate value when a box is clicked. The box is then essentially a button. Having looked through your code I'm not really sure what you are trying to acheive. Changing the border if something is clicked doesn't need a form - do you need to record the fact that someone has clicked - does it mean something further down the line?
That code is pure and utter gibberish. How about you try to explain what you're trying to do instead?
Here's what I think he's trying to do... https://jsfiddle.net/5nwpvky8/ but without a real life business problem to solve I'm just reading between the lines.
You could just style a simple form checkbox: <input type="checkbox" id="option1" name="option1"> <label for="option1">Option 1</label> input[type="checkbox"] { display: none; } input[type="checkbox"] + label { display: inline-block; width: 256px; height: 400px; margin: -1px 4px 0 0; vertical-align: middle; background: url(check.gif) left top no-repeat; cursor: pointer; } input[type="checkbox"]:checked + label { background: url(check.gif) -256px top no-repeat; } Code (markup): You should check css rules to fit your design.