Generate query string using jquery, javascript OR PHP
i have a form that users can fill out and i need the users to be able to generate a pdf with their results using query string example
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<form id="form">
<select name="test" id="test">
<option id="op1" value="1">1234</option>
<option id="op2" value="2">2134</option>
</select>开发者_如何学Go
</form>
<a href="url.pdf?Name=[FillStringHere]"> click here</a>
</body>
Thanks!
HTML:
<a href="#" id="pdf_a">click here</a>
jQuery
$(document).ready(function(){
$('#pdf_a').click(function(){
$(this).attr('href', 'url.pdf?'+$('#form').serialize());
});
});
Example:
http://jsfiddle.net/NeL5X/
This will take the values opt1 and opt2 and put it in the url as opt1=x&opt2=y.
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#my_link").click(function(){
opt1 = $("#opt1").val(); // Stores the value of id-opt1 in the variable opt1
opt2 = $("#opt2").val(); // Stores the value of id-opt2 in the variable opt2
url = "url.pdf?opt1=" + opt1 + "&opt2=" + opt2; // Takes the above variables and creates the query to send to your file.
window.location = url;
});
});
</script>
</head>
<body>
<form id="form">
<select name="test" id="test">
<option id="op1" value="1">1234</option>
<option id="op2" value="2">2134</option>
</select>
</form>
<a id="my_link"> click here</a>
</body>
精彩评论