Supporting each other

Community forums

Welcome, Guest
Username: Password: Remember me
The place for more technical questions for those who want to create new pagetypes or bespoke functionality.
  • Page:
  • 1

TOPIC:

Useful Code Snippets 6 years 4 months ago #5157

  • helenmd
  • helenmd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 77
  • Thank you received: 5
Hi all,

I'm not sure if this is the correct place for this, or whether it should be in the Creating Effective Materials section, but following sessions at the training day and the Xerte conference about coding and adding extra code and javascript to Xerte learning objects, I thought it might be a good idea to start a thread to share useful tips and bits of code that could be used in Xerte.

I will contribute some when I've sorted mine out, but if you are posting code, please could you indicate what it does, and if possible, attach a screenshot.

Thanks
The following user(s) said Thank You: GraemeS

Please Inloggen or Create an account to join the conversation.

Useful Code Snippets 6 years 4 months ago #5185

  • Fay
  • Fay's Avatar
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 229
  • Thank you received: 92
Not a complicated bit of code but adding this link will refresh the project. It's useful if you are using variables in questions & want the project to be refreshed so that the variables are recalculated & the question will update
<a href="#" onclick="location.reload()">Try again</a>
The following user(s) said Thank You: ymoore

Please Inloggen or Create an account to join the conversation.

Useful Code Snippets 6 years 4 months ago #5191

  • ymoore
  • ymoore's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 96
  • Thank you received: 14
Hi

I found this on the web and used it for an activity where users had to practice composing a tweet. It does the character countdown.
<style type="text/css">.over {
  color: red;
  }
</style>
<script type="text/javascript">maxCharacters = 140;
  $('#count').text(maxCharacters);
  $('textarea').bind('keyup keydown', function() {
    var count = $('#count');
    var characters = $(this).val().length;
    if (characters > maxCharacters) {
      count.addClass('over');
    } else {
      count.removeClass('over');
    }
    count.text(maxCharacters - characters);
  });
</script>
<p>&nbsp;
</p>
<p><span style="font-size:12px;"><i>You have <span id="count"></span> characters remaining</i></span>
</p>

Please Inloggen or Create an account to join the conversation.

  • Page:
  • 1
Moderators: JohnSmith
Time to create page: 0.046 seconds
Copyright © 2024 The Xerte Project.
Xerte logo Apereo logo OSI Logo

Search