JSFiddle - React, Tailwind, and code Playground
JavaScript
//var tempUrl = "https://lacinfo.motorolasolutions.com/LP=1486?q1=c&q2=c&q3=e&q4=f&q5=d&q6=d&q7=c&q3-other=Testing&&Testing&q4-other=testing & Agaon this is&q6-other=12345678906";
var tempUrl = "https://lacinfo.motorolasolutions.com/LP=1486?q1=c&q2=c&q3=e&q4=f&q5=d&q6=d&q7=c&q3-other="+encodeURIComponent("Testing&&Testing")+"&q4-other="+encodeURIComponent("testing & Agaon this is")+"&q6-other=12345678906";
console.log(tempUrl);
//This is URL of page
//var tempUrl = window.location.href;
//This is final value of string. Initially empty
var answerSet = [];
/*
* To get Question/Answer pairs, we'll first split URL with '?' which will give us an array of strings.
* like ['https://lacinfo.motorolasolutions.com/LP=1486','q1=a&q2=b&q3=e&q4=c&q5=b&q6=a&q7=a']
* We will pick 1st value of array & again split it with '&'
* so next array will be ['q1=a','q2=b'...& so on]
*/
var qaArray = tempUrl.split('?')[1].split('&');
//This is pre-defined array of question & answers
var questionAnswer = [
{
"question": "How many users do you have on your communications network?",
"options": {
"a": "1-25",
"b": "26-99",
"c": "100+"
}
},
{
"question": "How many communication devices do each of your users carry?",
"options": {
"a": "1 device",
"b": "2 devices",
"c": "3+ devices"
}
},
{
"question": "What is your main reason for using two-way communications?",
"options": {
"a": "Reliable anytime, anywhere service that fills gaps in 3G/4G cellular coverage",
"b": "Employee safety",
"c": "Durability and ruggedness",
"d": "Cost-effectiveness",
"e": "Other"
}
},
{
"question": "Which data application is most important for your workers' on-the-job success?",
"options": {
"a": "Work order ticketing",
"b": "Voice dispatch",
"c": "Text Messaging",
"d": "Email",
"e": "Custom-built apps",
"f": "Other"
}
},
{
"question": "What is...