Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Dec 15, 2011 @ 21:07
    Bjarne Fyrstenborg
    0

    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';}" />

    <input type="text" name="quantity" class="quantity" value="1">
       <xsl:attribute name="onfocus">if(this.value == '1') { this.value = '1'; }</xsl:attribute>
       <xsl:attribute name="onblur">if (this.value == '') {this.value = '1';}</xsl:attribute>
    </input>

    Bjarne

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 15, 2011 @ 21:49
    Jan Skovgaard
    1

    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

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 15, 2011 @ 21:50
    Chriztian Steinmeier
    2

    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:

    <input onblur="if (this.value == '') {{ this.value = '1'; }}" />

    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

     

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Dec 15, 2011 @ 22:21
    Bjarne Fyrstenborg
    0

    @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

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Dec 15, 2011 @ 22:26
    Bjarne Fyrstenborg
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft