Using jQuery with custom form asset

Hi, I'd like to get the window/browser size (and possibly more info regarding the users device) when submitting a custom form built in Squiz Matrix.

 

Is there a way to achieve this using jQuery or JavaScript, or even a global keyword? I've tried "var windowsize = $window.width(); jQuery("#res").text(windowsize);" and other variants but nothing seems to work.

 

Thanks in advance for the assist.  

Dave

What doesn't seem to be working? Are you making sure you are using the jQuery ready method?

Hi Nic, thanks for the reply.

 

I managed to get it to work with:

<script type="text/javascript">   $(function () {
    var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
    $("#%question_id_54566_q7%").val(width);
  });
</script>

 

I was using the incorrect keyword replacement to get the id of the form field.

 

Thanks for your help.

 

Dave