0

Im using web2py for a project and have to use ajax/javascript with a form. Currently when the user makes a selection in the departure choice box the arrival choice box appears. However im not sure how I would go about refining the list of the arrival choices based on what was selected in the first box.

For example if you had option 1, option 2 and option 3 in departure choice and option 2 was selected then only option 1 and 3 would be avaialbe in arrival.

makeBooking.html

{{extend 'layout.html'}}

{{block content}}

<div class="span8">
<div class="pagetitle">
       <h3>Make a Booking</h3>

</div>
<!-- Brandons Code Here -->
<select id="departureChoice">
{{for StopLocation in result:}}

<option value="{{=StopLocation.suburb_name}}">{{=StopLocation.suburb_name}}</option>

{{pass}}
</select>

<br>
<div id="arrive" style="visibility:hidden" >
    <select id="arriveChoice">
   {{for StopLocation in result:}}

<option value="{{=StopLocation.suburb_name}}">{{=StopLocation.suburb_name}}</option>

{{pass}}
</select>
</div>
<br>

{{end}}

<script type="text/javascript">
$('#departureChoice').change(function(event) {
    $.post('bookingFunction.html', { 
        selected: $('#departureChoice').val() 
        },
        function(data) {

            document.getElementById( 'arrive' ).style.visibility = 'visible';

        }
    );            
}); 

Using web2py would it be possible to then submit these two fields to query a database without reloading the page using ajax? I currently have bookingFunction.html set up for this but its blank.

Thanks in advance

1 Answer 1

2

This works:

http://www.web2pyslices.com/slice/show/1724/cascading-dropdowns-simplified

or

another recipes in http://www.web2pyslices.com/slice/search?q=cascading

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.