Skip to main content
Inspiring
April 18, 2016
Answered

Removing spaces from text entries with javascipt (2016)

  • April 18, 2016
  • 1 reply
  • 261 views

Hello,

I'm hoping someone could help me with a script or even a regular to remove the blank spaces between words in the text entry boxes.  I found this thread from 3 years ago, but the code doesn't seem to work - I'm using Captivate 9:

Removing spaces from text from text entry box

At the time the solution posted was:

var objCP = document.Captivate; 

var jsTextEntry = objCP.cpEIGetValue('TextEntryBox1');  
var jsNoSpaces = jsTextEntry.replace(/ /g,'');

objCP.cpEISetValue('varNoSpaces', jsNoSpaces);

But again, this doesn't work for me. Any suggestions? Thanks.

Bill

    This topic has been closed for replies.
    Correct answer bills89323792

    Never mind, I think I figured it out. For future reference, this seemed to work - changes the multi-word cpQuizInfoStudentName to OneWordName without spaces: 

    var getName = window.cpAPIInterface.getVariableValue( "cpQuizInfoStudentName" );

      

    var newName = getName.replace(/ /g,'');

          window.cpAPIInterface.setVariableValue('v_OneWordName', newName);

    1 reply

    bills89323792AuthorCorrect answer
    Inspiring
    April 18, 2016

    Never mind, I think I figured it out. For future reference, this seemed to work - changes the multi-word cpQuizInfoStudentName to OneWordName without spaces: 

    var getName = window.cpAPIInterface.getVariableValue( "cpQuizInfoStudentName" );

      

    var newName = getName.replace(/ /g,'');

          window.cpAPIInterface.setVariableValue('v_OneWordName', newName);