thanks for the example, i test it and work, btw, when i try using another 
example is not work (no error occured, but the result is not expected 
(nothing happen) ).
e.g. taken from 
http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation

my code
*controllers/defaut.py*
def test():
    btn = BUTTON('Try It', _type = "button", _onclick = """getLocation()""" 
)

    scr = SCRIPT("""
    var x = document.getElementById("demo");

    function getLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else { 
            x.innerHTML = "Geolocation is not supported by this browser.";
        }
    }

    function showPosition(position) {
        x.innerHTML = "Latitude: " + position.coords.latitude + 
        "<br>Longitude: " + position.coords.longitude;  
    }
            """
            )

    return dict(btn = btn, scr = scr)

*views/default/test.html*
{{extend 'layout.html'}}

{{=btn }}

{{=scr }}

{{=DIV(_id='demo')}}

how to achieve it using web2py way?

thanks and best regards,
stifan

On Monday, August 17, 2015 at 7:18:12 AM UTC+7, Val K wrote:
>
> Just for fun - paste in any controller and go to  .../sql_frm_js
>
> def sql_frm_js():
>     t_name='any_tbl' # just for more readable because SQLFORM.factory
>     f1_name='any_fld_1'
>     f2_name='any_fld_2'
>     f_id=lambda f, t=t_name: '%s_%s'%(t, f) # return id of html 
> INPUT-element corresponding to field name
>     
>     btn1=BUTTON('Click me', _type="button", _onclick ="""$('#%s').val('any 
> value') """%f_id(f1_name) )
>     btn2=BUTTON('And me', _type="button", _onclick ="""$('#%s').val( 
> your_JS_fun() ) """%f_id(f1_name) )
>
>     scr=SCRIPT("""
>     $(document).ready(your_JS_fun_init );
>     
>     function your_JS_fun_init()
>     {
>          $('#%s').val('Hi, I am your_JS_fun_init');
>          return 
>     };
>     
>     function your_JS_fun()
>     {
>          return 'Hi, I am your_JS_fun';
>     };
>             """%f_id(f2_name)
>             )
>
>     frm=SQLFORM.factory(
>                         Field(f1_name, 'string', comment=DIV(btn1, btn2)), 
>                         Field(f2_name, 'string'),
>                         table_name=t_name)
>     if frm.process().accepted:
>         response.flash=frm.vars[f1_name]+','+frm.vars[f2_name]
>         
>     return dict(frm=frm, scr=scr)
>
>
>
>
> On Friday, August 14, 2015 at 3:23:17 AM UTC+3, 黄祥 wrote:
>>
>> hi,
>>
>> is it possible to pass javascript value into sqlform?
>>
>> ref:
>>
>> http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_error
>>
>> i want to know user location when create or update delivery function, yet 
>> landing in w3schools provide it into javascript value, but don't know how 
>> to put it on web2py sqlform.
>>
>> any idea how to pass javascript value into sqlform?
>>
>> just another idea, i think it's better to have request.geolocation in 
>> web2py core request
>>
>> best regards,
>> stifan
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to