jquery - javascript insert into form submit -


i'm trying send data via javascript through form, it's not working. ideas why?

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <form method="get" action="test.php"> <input id="myvar" type="hidden" name="albumid" />  <button type="submit" id="btnsubmit">submit</button> </form>  <script type="text/javascript"> $("#btnsubmit").click(function(){          var album = '11';     document.getelementbyid('myvar').value = album;    }); </script> 

test.php

<?php echo $_get["albumid"]; ?> 

there several issues:

  1. you're missing http: in src when loading jquery library
  2. since loading jquery use $('#myvar').val(album);. see more on val()

that being said try

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>  <form method="get" action="test.php">     <input id="myvar" type="hidden" name="albumid" />     <button type="submit" id="btnsubmit">submit</button> </form>  <script type="text/javascript">     $('form').submit(function() {              var album = '11';         $('#myvar').val(album);     }); </script> 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -