Re: How to implement a dropdownlist in CherryPy where selected item is returned as argument appended to current URL?

Michiel Overtoom <motoom-qWit8jRvyhVmR6Xm/[email protected]> Tue, 14 May 2019 18:07:39 +0200
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
Hi,

> On 2019-05-14, at 17:12, Jibun no Kage <[email protected]> wrote:
>=20
> No one, that I have seen so far, appears to do a drop down list with just=
 straight HTML

What do you mean by 'straight HTML'? Does that allow for JavaScript code in=
 the 'onchange' event handler?


> The closest you can get is to use a drop down list and then a submit butt=
on... but that is not the requirement as noted in my topic.

If you want to avoid a separate submit button, you can have the 'onchange' =
event of the dropdown submit the form. I use this principle on a webapp I w=
rote, https://www.learnit.nl/inschrijving . When you select a training, the=
 form gets submitted, and a new form is returned to the browser, with more =
dropdowns where you can select a date, a place etc...

I made this by adding an 'onchange' event to the dropdown, which causes the=
 webbrowser to submit the form as soon as the user chooses an item from the=
 dropdown: (as if the user has pressed the submit button)

  <form action=3D"/process" method=3D"post">
    <select id=3D"food" name=3D"food" onchange=3D"submit();">
      <option value=3D"23">Apple</select>
      <option value=3D"62">Banana</select>
      <option value=3D"19">Bread</select>
    </select>
    ...
  </form>


> Clearly, CherryPy has no native hook or method to do this, per the past d=
iscussion thus far.

That is correct, because this has nothing to do with what framework or lang=
uage you use to serve up the page. The HTML page is displayed in the webbro=
wser of the user. When the user interacts with the page, events are generat=
ed, and these events can execute JavaScript code in the page. This all happ=
ens on the PC of the user and the server won't see any of this. The JavaScr=
ipt code could for example, redirect the browser to another URL, or if the =
page contains a form, submit the form to the server.


> To add just one drop down list... we have to add an additional language?

No, that is not necessary. You just have to make your HTML a bit more dynam=
ic by providing event handlers. And these event handlers are usually writte=
n in JavaScript, because that language is built-in the webbrowser.

Greetings,


--=20
"You can't actually make computers run faster, you can only make them do le=
ss." - RiderOfGiraffes

--=20
You received this message because you are subscribed to the Google Groups "=
cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/=
cherrypy-users/8FE43B46-DFAB-4E88-96AD-DA6E31104CA6%40xs4all.nl.
For more options, visit https://groups.google.com/d/optout.