I am trying a custom AJAX like functionality.
I know, AJAX function in web2py is there.
But i need to populate the values of html elements by their IDs.
Not just show the result in a 'target' DIV.

1) Upon clicking the link, controller action is performed (via a
'onclick' js handler) using value from <input id='i1'>.
2) Returned result is assigned to a javascript variable.
3) Set the "value" of <input id='i2'> equal to that js-variable

----simplified code follows----
[Controller]
def lod():
    do some processing on "request.vars.i1"
    and calculate "emp_id"
    return emp_id
[/Controller]

[View]
{{extend 'layout.html'}}
<input type='text' value='type a value' id='i1' name='i1' />
<a href='#' onclick='populate()'>Load result via AJAX </a>
<br /><br />

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

<script>
function populate(){
var empid = "{{URL(('lod'))}}";
window.alert(empid);
$('#i2').val(empid);
}
</script>
[/View]

<input > with id='i2' is not getting populated.
Messagebox is also blank (no value of 'empid')
I am 100 % sure that 'empid' is returned from the controller.

Any suggestion on the same highly appreciated.

Thanks,

Vineet

Reply via email to