After using different paid web poll tools, I’ve recently started building simple custom web polls on websites to better control how they are displayed and bypass response limitations. You can do this with vanilla HTML, CSS, and JS.

 

Create your web poll and generate a HTML version

Firstly, create your web poll with Google Forms. I usually restrict this to one or two questions.

Once you’re happy with your poll, run the Google Form URL through a Form to HTML generator. I really like this one here. This will generate most of the code you need, with a few modifications.

The custom HTML should look something like this, with the form action sending to your Google Form URL.


<form action="{{Google Form URL}}/formResponse" target="no-target" onsubmit="newResponse()" method="post">
  <h4 class="form-title" for="2011118782">How likely are you to recommend this product to friends or family?</h4>
  <div class="form-group">
    <label class="radio-inline">
      <input type="radio" name="entry.1981247315" value="1" >1
    </label>
    <label class="radio-inline">
      <input type="radio" name="entry.1981247315" value="2" >2
    </label>
    <label class="radio-inline">
      <input type="radio" name="entry.1981247315" value="3" >3
    </label>
  </div>
</form>

 

Check if the poll was already displayed in the session

Optionally, you can use session storage to display the poll on the first page view of a user’s session. Although this method is more intrusive for a user, it’s much more likely you’ll get responses this way. I like to run this snippet of code for a few weeks to get a good amount of responses, then after you get significant data, revert the experience back to just a floating feedback tab that launches the poll.


// Assign a variable to the feedback form ID
webPoll = document.getElementById("embed_feedback_form");
// Check and set session storage, display popup on first page view
if (!window.sessionStorage.popupPoll) {
  openDelay = 8000;
  setTimeout(function() {
    webPoll.style.display = "block";
  }, openDelay);
  window.sessionStorage.popupPoll = true;
}

 

Provide a success message

When a user submits the form, we should provide a success message to the respondent, then hide the poll on the page so the user can continue browsing.


// Hide poll on page
function hidePoll() {
  webPoll.style.display = "none";
}
// Alert users that the poll was submitted
function newResponse() {
  alert("Thanks for your submission!");
  hidePoll();
}

 

Prevent the form from redirecting away from the website

Prevent the form from redirecting to Google Forms by setting the form target to “no-target” and embed this window location prevention just after the closing form tag. Set this to hide on display.


<iframe id="no-target" style="display: none;" src="https://www.w3schools.com/js/js_window_location.asp" name="no-target"></iframe>

 

Demos

Once you’ve deployed the code, you should start seeing poll responses come through to the Google Form you published.

If you want to see how the form works, check out my demo on Codepen. I’ve added a bit more styling to the form and its container, but you could include a CSS framework like Bootstrap to help manage the look and feel.

Alternatively, here is a demo for how you can create an even easier popup poll similar to Hotjar or Crazy Egg by embedding a Google Form directly into the page. It can either display on click of a button or launch after a delay.

If you like the demos, please fork the code and modify it as you want.

 

Zak Rowling