Skip to main content
Dirlo
Inspiring
May 22, 2023
Answered

Focus on a TEB when entering a slide

  • May 22, 2023
  • 6 replies
  • 1209 views

...

Hello Captivaters !...

I'm trying to put the focus on a TEB (Text_Entry_Box_1) when entering a slide... so that the learner don't have to click on the TEB to activate it...

So far I try many javascript code without success :

Solution 1 :

window.document.getElementById('Text_Entry_Box_1').focus();

Solution 2 :

$('Text_Entry_Box_1').focus();

Solution 3 :

$('#Text_Entry_Box_1').focus();

So... Some help would be appreciated !...

Thanks in advance !...

😉

...

    This topic has been closed for replies.
    Correct answer Stagprime2687219

    Perhaps the TEB is not ready - Try putting the focus within a timeout.

    Are you using a variable to address the specific ID of the TEB on each slide?

    My example below was for the Kiwi slide that I pulled up. TEB number 37

     

    6 replies

    Dirlo
    DirloAuthor
    Inspiring
    May 22, 2023

    ...

    Project updated !...

    As I had only 1 action to enter all the question slides, I fear I would have to create a new one for each slide... But I just add 1 action to my existing action :

    setTimeout(function(){

    $("#Text_Entry_Box_1_inputField").focus();
    $("#Text_Entry_Box_2_inputField").focus();
    $("#Text_Entry_Box_3_inputField").focus();
    ... ... ...
    $("#Text_Entry_Box_50_inputField").focus();
    $("#Text_Entry_Box_51_inputField").focus();
    $("#Text_Entry_Box_52_inputField").focus();

    }, 200);

     

    And it's ok !...

     

    Big thanks to all the helpers on this forum !... Without all of you, no doubt  I would have stopped using Captivate for long !!!...

    😉

    ...

    Stagprime2687219
    Legend
    May 22, 2023

    I have the same pen... LOL

     

    Dirlo
    DirloAuthor
    Inspiring
    May 22, 2023

    !!!!!!...

     

    Dirlo
    DirloAuthor
    Inspiring
    May 22, 2023

    ...

    As the problem should come from this, here is the javascript code I use to go on a random slide :

     

    var pages1 = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53'];

    function GoTo1(){
    if(pages1.length){
    let randomNumber = Math.floor(Math.random() * pages1.length);
    let randomPages1 = pages1.splice(randomNumber, 1);
    cpAPIInterface.gotoSlide(randomPages1[0]);
    }
    }

     

    I try to use the javascript array, so I didn't go to the same slide 2 times...

    (This code is a personnal mixture of codes I found in the Captivate ressources, so even if it seems to work, I think the error is there ???... )

     

    😉

    ...

    Stagprime2687219
    Stagprime2687219Correct answer
    Legend
    May 22, 2023

    Perhaps the TEB is not ready - Try putting the focus within a timeout.

    Are you using a variable to address the specific ID of the TEB on each slide?

    My example below was for the Kiwi slide that I pulled up. TEB number 37

     

    Dirlo
    DirloAuthor
    Inspiring
    May 22, 2023

    It seems to work !!!...

    (Tested with only 3 slides !...)

    And one more time a BIG BIG thanks to you !!!...

    😉

     

     

     

    Dirlo
    DirloAuthor
    Inspiring
    May 22, 2023

    ...

    My helpers are here !!... Cool !!!...

    As I'm still in a pain !...

    To help you to understand my problem here is the project :

    https://soutien67.fr/tableau/CP/CP-FR-Alpha-1E/index.html

    (Nothing to download Lily, it's already online !)

    On the first question slide, the TEB is focused...

    But as I reach the second one (and the following), there is no more focused on the TEB... (I had to push the Tab button or click on the TEB...).

    The TEBs are always on top of the time line... and always on top of the order of the tabulations...

    I also try with the "inputField" in the Js code without any success...

    ...

    As I investigate I discover that the problem comes from the way I change slides... (I use Javascript to go on a hasardous slide), but if I change the action with "go to the next slide" all the TEB are focused as intended...

    ...

    Pfffff...

    !!!...

    😉

    ...

    sabre123
    Participating Frequently
    May 22, 2023

    You've got a problem somewhere in your code. Go to the above URL, open the Developer Tools and then open the Console window.

    Stagprime2687219
    Legend
    May 22, 2023

    Perhaps try using the following ID

    Text_Entry_Box_1_inputField

    Lilybiri
    Legend
    May 22, 2023

    By default a TEB has focus when entering the slide. How complicated is the slide that you do need JS? Can you show the timeline and the stage?

    Stagprime2687219
    Legend
    May 22, 2023

    If you have multiple TEBs on a slide - it could be useful to target a specific one.