thanks for replying.
I tried this-->
[Controller]
def lod():
    x = 'This is a val'
    return "$('#i2').val(x);"
[/Controller]

[View]
{{extend 'layout.html'}}
<input type='text' value='type a value' id='i1' name='i1' />
<a href='#' onclick="ajax({{=URL('lod')}}, ['i1'], ':eval');" >Load
result via AJAX </a>
<br /><br />

<input type='text' id='i2' name='i2' value='result here' />
[/View]

But the input with id='i2' is not populated.

Is something wrong or missing in the code?

---Vineet

On Nov 2, 6:12 pm, Anthony <abasta...@gmail.com> wrote:
> On Wednesday, November 2, 2011 6:14:04 AM UTC-4, Vineet wrote:
>
> > <script>
> > function populate(){
> > var empid = "{{URL(('lod'))}}";
>
> That's not how Ajax works -- you don't just assign a URL to a variable.
> Instead, you have to explicitly make an Ajax call. If the web2py ajax()
> function isn't suitable, you can use the jQuery .ajax() function
> (http://api.jquery.com/jQuery.ajax/). However, I think you can use the
> web2py ajax() function in this case, specifying the target as ":eval". That
> tells the function that the action will be returning some Javascript to be
> executed. So, do:
>
> onclick="ajax({{=URL('lod')}}, ['i1'], ':eval');"
>
> and have the lod action return:
>
> "$('#i2').val('whatever');"
>
> Anthony

Reply via email to