i have working dropdown menu, , can send value function using "submit" button. it's quite clumsy however, user has press button, wait page load , refreshes page user loses other "settings" made on page. have understood ajax solution this. read guide: http://www.web2py.com/books/default/chapter/29/11/jquery-and-ajax#the-ajax-function , tried few methods, never works.
so original working code. contents stripped , altered, basics same. view demo.html:
<form action="change_dropdown"> <select name="tables"> <option value="first_value">first</option> <option value="second_value">second</option> <option value="third_value">third</option> </select> <br><br> <input type="submit"> </form>
action:
def change_dropdown(): if request.vars.tables: session.tables = request.vars.tables else: session.tables = none session.main_warning= "incorrect parameters function: 'change_dropdown()'." redirect(url('demo')) return
then original action demo
session.tables
, on. turning ajax. want:
<form> <select name="tables", onchange="ajax('change_dropdown', [], '');"> <option value="first_value">first</option> <option value="second_value">second</option> <option value="third_value">third</option> </select> </form>
i did action: redirect(url('demo'), client_side=true)
mentioned in example. have no idea why it's needed however.
but don't know how send variable tables
action. if write inside python url
helper, crashes, because thinks it's python variable (where it's javascript variable (?)). if write inside ajax()
function's second parameter, halts , gives me weird error in js console:
uncaught error: syntax error, unrecognized expression: [name=[object htmlselectelement]]
if need more information can show full codes methods tried, think can take here.
you can send variable follows:
ajax("{{=url('change_dropdown')}}",['tables'],':eval')
redirect(url('demo'), client_side=true)
needed want redirect function have sent ajax request redirect not 'change_dropdown'
redirect.
edit:
<form> <select name="tables", onchange="ajax(\"{{=url('change_dropdown')}}\",['tables'],':eval') ;"> <option value="first_value">first</option> <option value="second_value">second</option> <option value="third_value">third</option> </select> </form>
Comments
Post a Comment