is there a way to write the code below direct in the attributes like this: <input type="text" name="quantity" class="quantity" value="1" onfocus"if(this.value == '1') { this.value = '1'; }" onblur"if (this.value == ' ') {this.value = '1';}" />
It goes without saying that this is of course much better handled in a separate JS file, using event delegation and whatnot, but you know that and this needs to be finished now :-)
@Jan Well I haven't much experience with javascript, but I would just avoid to let users send an empty string as quantity to the cart here: http://sub.ak-security.dk/da/shop/lygter/led-lenser-p7.aspx which is using Tea Commerce - they will fix this in the future versions of the starterkit, but if the value of the input field was empty the users will get an error popup message.. so this was a quick fix to using 1 as standard value.
Thanks for the suggestion with using variable.. when having more input fields it would be a better approach..
@Chriztian Thanks, that was what I was looking for.. I just get an error before, but is probably because it already is used as syntax in xslt..
Onfocus and onblur attributes
Hi..
is there a way to write the code below direct in the attributes like this:
<input type="text" name="quantity" class="quantity" value="1" onfocus"if(this.value == '1') { this.value = '1'; }" onblur"if (this.value == ' ') {this.value = '1';}" />
Bjarne
Hi Bjarne
why wo you want to create these events inline? Can't you specify these events in an external JavaScript instead?
If you absolutely need to mess around with JS in XSLT you should be able to achieve this by doing...
<xsl:variable name="onfocus">
<xsl:text>if(this.value == '1') { this.value = '1'; }</xsl:text>
</xsl:variable>
<xsl:variable name="onblur">
<xsl:text>if (this.value == '') {this.value = '1';}</xsl:text>
</xsl:variable>
<input type="text" name="quantity" class="quantity" value="1" onfocus="{$onfocus}" onblur="{$onblur}"/>
/Jan
Hi Bjarne,
I saw the XSLT sign on the nightly sky and jumped into my "XSLT-Man" suit to rescue you — or, erm - I mean, here's how you do that:
So, double-up on the curlies and you'll succeed.
It goes without saying that this is of course much better handled in a separate JS file, using event delegation and whatnot, but you know that and this needs to be finished now :-)
/Chriztian
@Jan
Well I haven't much experience with javascript, but I would just avoid to let users send an empty string as quantity to the cart here: http://sub.ak-security.dk/da/shop/lygter/led-lenser-p7.aspx which is using Tea Commerce - they will fix this in the future versions of the starterkit, but if the value of the input field was empty the users will get an error popup message.. so this was a quick fix to using 1 as standard value.
Thanks for the suggestion with using variable.. when having more input fields it would be a better approach..
@Chriztian
Thanks, that was what I was looking for.. I just get an error before, but is probably because it already is used as syntax in xslt..
Bjarne
But yes I could also do something like this: http://www.java2s.com/Code/JavaScriptReference/Event-Handlers-Reference/onBlurExample.htm
or write the code in an external javascript file.
Bjarne
is working on a reply...