-1

I am new to Cherrypy, Kindly help me how can I get the selected value from dropdown using cherrypy in python.

dario
  • 5,149
  • 12
  • 28
  • 32
Deepa Huddar
  • 321
  • 1
  • 4
  • 15

1 Answers1

1

I assume the dropbox is a element with id="dropDownId"; i assume the server call is done using jquery.

the value of the currently selected item is

$('#dropDownId').val();

the currently selected text:

$('#dropDownId :selected').text();

You can post it to the server with an ajax request:

    queryparams = $.param({     
                        "dropDownVal":$('#dropDownId').val(),
                        "email":$("#email").val(), 
                        "password":$("#password").val(), 
                    });

    $.ajax  ({
        url: '/login',
        type: "POST",
        data: queryparams,
    })

On the server side we have a cherrypy funcion, exposed to receive requests for the "login" page:

class mainPage():

@cherrypy.expose
def login(self,password=None,email=None,dropDownVal=None):

    self.password = password
    self.email = email.strip().lower()
    self.dropDownVal = dropDownVal

    cherrypy.log(self.dropDownVal)

    return "login ok"

It expects 3 optional parameters (email,password,dropDown), logs the "dropDownVal" and returns the string "ok" to the browser.

Marco Rossi
  • 736
  • 7
  • 7
  • Credits to http://stackoverflow.com/questions/2780566/get-selected-value-of-a-dropdowns-item-using-jquery for the javascript part. – Marco Rossi May 28 '15 at 13:28