We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10395
    • 96 Posts
    Hi,

    Was just wondering if you can use javascript in the snippets? Here is the javascript i’m trying to get working, unless i have it wrong embarrassed

    <textarea id="reason" name="reason" onclick="javascript:document.this.value=\'\';">this text should be removed after the mouse clicks the textbox</textarea>
    


    I’m trying to get the textbox to clear when it’s clicked....

    Also, on the same subject, is there anyway to reference a pre-made javascript function from perhaps a seperate .js file that is included somewhere? or how does that work?

    Thanks.
    • Hi Gaia,

      For the textarea, you are nearly there. You just need to remove the ’document.’ from the onclick event:

      <textarea id="reason" name="reason" onclick="javascript:this.value=\'\';">this text should be removed after the mouse clicks the textbox</textarea>


      For the external js, as long as you include a call to the external js file in the <head> part of your template, then you can use the functions contained within the file.

      You could use $modx->regClientStartupScript to place the necessary code automatically in the head on any page the snippet is used - but you will need to apply a fix (run a search in this forum and you’ll find the details) to make this work.

      Hope that helps, Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com