Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Pre-fill a Numeric Q with a “£” symbol?

I have followed the advice here
https://sawtoothsoftware.com/forum/9995/currency-question?show=9995#q9995

 to constrain the decimal places for currency values in a numeric question (‘val’):
 
 
$(document).ready(function(){
    var response = $('#val').val();
    var regex = /\.[0-9][0-9]$/;
     
    if (!regex.test(response))
    {
        strErrorMessage = 'Error text here.';
    }
}) 


I would like to pre-fill the response box with a “£” symbol on the left.

Is that possible with a numeric Q? – I think it’s been done in a Grid Q:

https://sawtoothsoftware.com/forum/11342/column-input-labels?show=11342

thanks
Dan
asked Oct 13, 2016 by dan r Bronze (1,550 points)

1 Answer

0 votes
 
Best answer
Put these codes in your question footer:

<script>
$(document).ready(function(){
    $('#NumericQ_div input').wrap('<span class="currencySpan"></span>');
    $('.currencySpan').prepend('£');
})
</script>


<style>
.currencySpan {
    border: 1px inset #ccc;
}

.currencySpan input {
    border: none;
}

.currencySpan input:focus {
    outline: none;
}
</style>


"NumericQ" should be replaced with the numeric question's name.

Does this look sufficient for you?  I can keep experimenting with the CSS if you want to modify how it looks.
answered Oct 13, 2016 by Zachary Platinum Sawtooth Software, Inc. (84,025 points)
selected Oct 13, 2016 by dan r
That works  and looks fine to me Zachary - thank you

Would you be able to give the code to implement the same in a Grid Q set up for numeric input?

thanks
Dan
If you have removed the alternating colors from the grid question, you can probably use almost the exact same code.  Instead of "#NumericQ_div input", you need this:

#GridQ_div .inner_table input


If you are using background colors in the grid, though, more CSS may be necessary to make it look good.
works for me, as is.

thanks
Dan
...