hmmmm..
Seems that I need to return js code from controller.
btw, I have found a one-line jquery code for this-->

"$('#element_id option[value=%s]').attr('selected', 'selected');" %
dict_obj['key']

This works & I will proceed with this, for time being.
Thanks for your responses Anthony.

--- Vineet

On Nov 8, 7:31 pm, Anthony <[email protected]> wrote:
> I think you need .options[i] rather than .options(i). Anyway, it's
> generally easier to do this kind of thing with jQuery rather than raw
> Javascript.
>
> Anthony
>
>
>
> On Tuesday, November 8, 2011 9:04:41 AM UTC-5, Vineet wrote:
>
> > Something is wrong in the function.
> > I defined a test js function in View.
>
> > function alrt(mesg) {
> > alert(mesg) };
>
> > And in Controller,
> > return "alrt('Hello World!');"
>
> > It works.
>
> > The actual js function is---
> > (it sees which value of select box matches the one returned from
> > controller; then sets the value of select box to that value).
>
> > function selbx(elementID, value_returned_from_dataset){
> >             for (i=0;i<document.getElementById(elementID).length;i++)
> >              {
> >                 if (value_returned_from_dataset ==
> > document.getElementById(elementID).options(i).text)
>
> > {document.getElementById(elementID).options(i).selected = true;
>
> >                      }}}
>
> > In controller---
> > return "selbx('id_of_element','%s');" % dict_obj['freq']
>
> > dict_obj['freq'] is non-blank.
> > It is a string itself.
> > ****************************************
> > If individual code-lines are returned, it works.
> > ****************************************
>
> > Any guess why so?
>
> > Regards,
> > Vineet
>
> > On Nov 8, 6:44 pm, Anthony <[email protected]> wrote:
> > > On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote:
>
> > > > > If 'myvar' is a Python variable, you're going
>
> > > > 'myvar' is a not a python variable.
> > > > I pass the id of html element as argument.
> > > > Javascript code sets the value of that html element.
>
> > > OK, but same problem -- 'myvar1' isn't a javascript variable either --
> > it
> > > is a string identifying an html element. So you would still have to
> > return
> > > 'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are
> > using
> > > it in the code.
>
> > > Anthony

Reply via email to