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:
- you're missing
http:
insrc
when loading jquery library - since loading jquery use
$('#myvar').val(album);
. see more onval()
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
Post a Comment