Randomly generate number according to previous text entry answer | XM Community
Skip to main content
Question

Randomly generate number according to previous text entry answer


Hi guys, I have this very specific scenario that requires a randomly generated number according to a text entry. Here's a brief description: Screen 1: _How much do you expect to sell this item?_ [positive number-only entry], let's say respondent enters 5000 Screen 2: _Buyer proposes to buy your item for_ [a randomly generated number between 0 and the entered number in Screen 1] (so between 0 and 5000). _Would you accept the offer_? I can't figure out how to generate the number in Screen 2. I tried random number generation in piped text but it didn't work. Thanks a lot in advance!!

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5916 replies
  • August 10, 2019
The problem is probably that you can't nest pipes. You can do it in JavaScript: ``` var randNum = (parseInt("${q://QID1/ChoiceTextEntryValue}") * Math.random()).toFixed(0); ```

TomG, thank you! I tried this in various what but somehow didn't get it to show up correctly. Could you please let me know how I can insert exactly this in between _Buyer proposes to buy your item for_ [BLANK] _Would you accept the offer?_

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5916 replies
  • August 20, 2019
> @vinhpham194 said: > TomG, thank you! I tried this in various what but somehow didn't get it to show up correctly. Could you please let me know how I can insert exactly this in between _Buyer proposes to buy your item for_ [BLANK] _Would you accept the offer?_ > html: ``` Buyer proposes to buy your item for <span class="randNum"></span>. Would you accept the offer? ``` JS: ``` jQuery("#"+this.questionId+" .randNum").html(randNum); ```

Leave a Reply