You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Teruhiko Kurosaka <Ku...@basistech.com> on 2007/05/22 01:00:08 UTC

How to handle hl.fl form variable (any variable with a dot in its name) from javascript?

I have a form that sets the hl.fl form hidden variable.
I wanted to change the higlighted field depending on the
query string that is typed, using JavaScript.
This is normally done by the JavaScript code like this:
	document.myform.varname.value = "whatever"
But this doesn't work for hl.fl because the name of
the variable includes a dot that JavaScript interprets
as a layer separator:
	document.myform.hl.fl.value
would be interpreted as document.my form.hl's
subelement named fl.  I tried this but it didn't work:
	document.myforom.hl\u002Efl.value

Is there any other way to change the form variable
named hl.fl?

For the futuer versions, may I suggest removing the
dots from this and other variables?

-kuro

RE: How to handle hl.fl form variable (any variable with a dot in its name) from javascript?

Posted by Chris Hostetter <ho...@fucit.org>.
: But I am now hitting the similar problem with XSLT. The
: following XSLT code can't retrieve the value of "hl.fl"
: parameter even though the similar code for other parameter
: works.
:
: <xsl:variable name="hlfl"
: select="response/responseHeader/lst[@name='params']/str[@name='hl.fl']"
: />

i just added that snipped to the example.xsl, and then echoed the value of
$hlfl later in the page and it worked fine for me -- but only when using
the "version=2.1" param since the XmlResponseWriter format version change
from 2.1 to 2.2 chnges the responseHeader format to be a named list like
everything else, perhaps this will work better for you...

  <xsl:variable name="hlfl" select="//response/lst[@name='responseHeader']/lst[@name='params']/str[@name='hl.fl']"

..that will match the XML version=2.2 format (which is the default in the
trunk)

: I really don't think using a dot in variable names
: is a good idea.

thinking of it as a variable name is a bad idea, becuase it is not a
variable name, it's a URL querystring/CGI paramater name.  when modeling a
URL (regardless of language) param names should never be treated as
"variables" they should be treated as string keys in "map" like data
structures -- any character is legal: periods, spaces, ampersands, equals
signs ... they are all fair game, so languages that have any sane concept
of a URL know better then to treat them as variable names.



-Hoss


Re: How to handle hl.fl form variable (any variable with a dot in its name) from javascript?

Posted by Mike Klaas <mi...@gmail.com>.
On 22-May-07, at 11:38 AM, Teruhiko Kurosaka wrote:

> Ryan,
> Thank you.  The JavaScript code you mentioned works well.
>
> But I am now hitting the similar problem with XSLT. The
> following XSLT code can't retrieve the value of "hl.fl"
> parameter even though the similar code for other parameter
> works.
>
> <xsl:variable name="hlfl"
> select="response/responseHeader/lst[@name='params']/str 
> [@name='hl.fl']"
> />
>
> I am using the XSLT Writer and whatever XSLT processor
> it uses.
>
> I can get around this problem by passing the same
> value to another parameter of no dot in its name, but
> I really don't think using a dot in variable names
> is a good idea.

I don't know XPath well enough to help you solve you problem, but '.'  
is perfectly legal in xml attribute values and has a long tradition  
of use in separating semantic components of a name in programming  
languages.

Note that the URL parameter is not a variable in Solr.  Your problems  
seem to be occurring due to the use of systems that attempt to map  
data to variable names, which seems to me like a worse idea than  
using '.' in url paramters.

regards,
-Mike

RE: How to handle hl.fl form variable (any variable with a dot in its name) from javascript?

Posted by Teruhiko Kurosaka <Ku...@basistech.com>.
Ryan,
Thank you.  The JavaScript code you mentioned works well.

But I am now hitting the similar problem with XSLT. The 
following XSLT code can't retrieve the value of "hl.fl" 
parameter even though the similar code for other parameter 
works.  

<xsl:variable name="hlfl"
select="response/responseHeader/lst[@name='params']/str[@name='hl.fl']"
/>

I am using the XSLT Writer and whatever XSLT processor
it uses.  

I can get around this problem by passing the same
value to another parameter of no dot in its name, but
I really don't think using a dot in variable names
is a good idea.

-kuro  

Re: How to handle hl.fl form variable (any variable with a dot in its name) from javascript?

Posted by Ryan McKinley <ry...@gmail.com>.
Teruhiko Kurosaka wrote:
> I have a form that sets the hl.fl form hidden variable.
> I wanted to change the higlighted field depending on the
> query string that is typed, using JavaScript.
> This is normally done by the JavaScript code like this:
> 	document.myform.varname.value = "whatever"
> But this doesn't work for hl.fl because the name of
> the variable includes a dot that JavaScript interprets
> as a layer separator:
> 	document.myform.hl.fl.value
> would be interpreted as document.my form.hl's
> subelement named fl.  I tried this but it didn't work:
> 	document.myforom.hl\u002Efl.value
> 
> Is there any other way to change the form variable
> named hl.fl?
> 

can't you use something like:

document.forms["FormName"].elements["Input.Name"].value

or:

<input id="myhlfield" ...>

document.getElementById( "myhlfield" ).value


> For the futuer versions, may I suggest removing the
> dots from this and other variables?
> 

the dot syntax is used in many places, and can't easily be removed...

ryan