Create 'dynamic' images using JS
I've a form with 2 fields. How to create a new image with the values from these 2 fie开发者_JS百科lds in the query part of the "src" URL upon form submission?
See this example (using jQuery):
<form id="myform">
<input type="text" value="" id="input1">
<input type="text" value="" id="input2">
<input type="submit" value="submit">
</form>
<img id="image" src="http://mydomain.com/empty.gif" />
<script>
$(document).ready(function () {
$("#myform").submit(function (ev) {
ev.preventDefault();
var val1 = $("#input1").val();
var val1 = $("#input2").val();
$("#image").attr("src", "http://mydomain.com/image?val1="+val1+"&val2="+val2);
});
});
</script>
change mydomain.com to you host or relative path.
精彩评论