dropdown lists click or not
I'm new to jquery and I 'm facing a prob since I have two dropdown lists and I want to accomplish the following:
I want,according to user's choices, some fields of my form to be completed. I do that with this code:
- <script type="text/javascript">
- $(document).ready(function() {
- $('#id_veh_id1').bind('click', function () {
- $('#id_veh_id2').bind('click', function () {
- var val1 =$("#id_veh_id1").val();
- var val2 =$("#id_veh_id2").val();
- $.get(""+val1+"/"+val2+"/", function(data) {
- vlength=data.veh_length;
- vwidth=data.veh_width;
- vheight=data.veh_height;
- v1type=data.v1_type;
- v2type=data.v2_type;
- document.getElementById('id_vlength').value=vlength;
- document.getElementById('id_vwidth').value=vwidth;
- document.getElementById('id_vheight').value=vheight;
- document.getElementById('id_type1').value=v1type;
- document.getElementById('id_type2').value=v2type;
- });
- });
- });
- });
- but I can't manage the situation when the user doesn't select anything from the second list. In that case with my code nothing happens. Instead I want only the choice of the first list to be considered and for val2 I want to pass a null/none value. What can I do?