Dynamic dropdwon without js

136 views
Skip to first unread message

Tomas Schertel

unread,
Jun 19, 2012, 11:57:21 AM6/19/12
to we...@googlegroups.com
Is there a way to create dynamic dropdowns without javascript?
I though some thing like call a python/webpy function on onchange event to populate a second dropdown,
Has someone tested/tried it?

Thanks.

Shannon Cruey

unread,
Jun 19, 2012, 2:33:54 PM6/19/12
to we...@googlegroups.com
I don't think it's gonna be possible without javascript.  The onchange event of a select element *is* javascript as you know.

In my experience it's most efficient to use jQuery, bind an ajax call to the change event, and update/display the second box in the callback.  That's the "web2.0" way.  Upside - no page refreshes.  Downside - pretty robust client side code.

If you're feeling more oldschool (php/asp'ish), you could with minimal javascript have the onchange event simply post the entire form, and on the server look at the posted fields and determine what to deliver back.  Upside - minimal client javascript.  Downside - full page roundtrips on field changes are a suboptimal user experience, they tend to annoy users and mess with the browser history.

A third option (I almost didn't even mention because it's exactly the opposite of your original question) is to populate the initial page with all the data you need for every combination, then do your user experience completely in javascript.  If it's not a ton of data this is easy and efficient, and pretty dang safe now that all modern browsers are basically "pitfall free".

It really depends on which method will best fit the rest of your application.

If you avoid javascript because it's annoying, I totally agree - it is.  But jQuery changed my life, and if you're not familiar with it the payoff is well worth the learning curve.

S


--
You received this message because you are subscribed to the Google Groups "web.py" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/9Rha76ONtYIJ.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.

Tomas Schertel

unread,
Jun 19, 2012, 3:39:33 PM6/19/12
to we...@googlegroups.com
Do you have an working example using jquery + webpy?

Thanks.
To unsubscribe from this group, send email to webpy+unsubscribe@googlegroups.com.

Shannon Cruey

unread,
Jun 19, 2012, 5:35:34 PM6/19/12
to we...@googlegroups.com
Does anyone know how to create a new "cookbook" on the web.py site?  What I'm about to say is the sort of thing I wish I'd had 12 weeks ago.

jQuery is a javascript "helper" framework that has changed my life in web development.  My application is 100% static html pages, with jquery ajax webmethods being served by web.py.  I don't use templating except so I can have a sort of "master" page header and footer.  The rest is pure ajax client/rest server.

Attached are two files that demonstrate doing jQuery ajax from a web.py server.  I've included jquery from google code to make the example work - if you like you can include jquery locally in your directory with your other script.

Put the index.html file in the /static directory, and then run main.py.

I'll put this all in a cookbook if someone will guide me how.
S






To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/GdgtUhH8v9EJ.

To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
index.html
main.py

Xavier Combelle

unread,
Jun 19, 2012, 2:32:10 PM6/19/12
to we...@googlegroups.com
Le 19/06/2012 17:57, Tomas Schertel a �crit :
How do you call python without javascript in onchange event ?
Reply all
Reply to author
Forward
0 new messages