Neveen
Neveen

Reputation: 2175

write python inside jquery

I have a web2py application and am using jQuery to validate data. I want to write Python code inside jQuery. How can I do that?

if($("#myform_parent_id")[0].value != '' 
    && $("#myform_parent_birthdate")[0].value != ''
    && 
      // Here I want to write Python code
  ..
}

Because when i make this code inside controller and then return the form it is reset selected values.

Upvotes: 0

Views: 1955

Answers (3)

Stephen Ellis
Stephen Ellis

Reputation: 11

Silverlight allows you to embed Python as a scripting language on the client-side. http://www.voidspace.org.uk/ironpython/silverlight/index.shtml

Upvotes: 1

hoju
hoju

Reputation: 29452

If you define this code in the view (instead of the controller) then you can use Python code within {{ }} blocks.

Upvotes: 1

Arjan
Arjan

Reputation: 23559

As no browser will understand Python, you'll have to make an Ajax call to the server if you really want to use Python. This will probably complicate things for you, if only as Ajax calls are asynchronous by definition. But jQuery does support it.

Alternatively, to keep it all within the browser, you need JavaScript-only. If you can't translate your Python to JavaScript yourself, you could take a look at automated conversions.

Upvotes: 0

Related Questions