javascript - Using URL from email merge to populate web form text box using Java Script -


i'm using mailchimp merge fields url directing people complete form on site. want prepopulate text boxes information url.

ex: http://www.sitename.com/page?fname=john&lname=smith&email=jsmith@email.com

i'm novice @ , not sure i'm doing wrong here. here's core code:

<head>  <script> $.extend({   geturlvars: function(){     var vars = [], hash;     var hashes = window.location.href.slice(window.location.href.indexof('?') + 1).split('&');     for(var = 0; < hashes.length; i++)     {       hash = hashes[i].split('=');       vars.push(hash[0]);       vars[hash[0]] = hash[1];     }     return vars;   },   geturlvar: function(name){     return $.geturlvars()[name];   } }); </script>  </head>  <body>      <form id="form_id_name" method="post" action="/forms/users">      <label for="fname">first name:</label>     <input required="" class="text" id="user_first_name" name="user[first_name]" type="text" />  <script> $("#user_first_name").val($.geturlvar("fname")); </script>        <label for="lname">last name:</label>     <input class="text" id="user_last_name" name="user[last_name]" type="text" />  <script> $("#user_last_name").val($.geturlvar("lname")); </script>        <label for="email">email address:</label>     <input class="text" id="user_email" name="user[email]" type="email" />  <script> $("#user_email").val($.geturlvar("email")); </script>       <input type="submit" name="commit" value="submit" />    </form>  </body> 

the problem is, @mike mccaughan mentiones, extending nothing. far can see used function, trying create jquery function/plugin. try instead

$.fn.extend({    geturlvars: function(){      var vars = [], hash;      var hashes = window.location.href.slice(window.location.href.indexof('?') + 1).split('&');      for(var = 0; < hashes.length; i++)      {        hash = hashes[i].split('=');        vars.push(hash[0]);        vars[hash[0]] = hash[1];      }      return vars;    },    geturlvar: function(name){      return $.geturlvars()[name];    }  });


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -