Conversion from jQuery into JavaScript -
i've script:
<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>
how if written in javascript?
<img id="image" src="http://mydomain.com/empty.gif" /> <script> window.onload = function() { // not browsers support domcontentloaded document.getelementbyid("myform").onsubmit = function() { var val1 = document.getelementbyid("input1").value; var val2 = document.getelementbyid("input2").value; document.getelementbyid("image").src="http://mydomain.com/image?val1="+val1+"&val2="+val2; return false; }; }; </script>
if name fields can use
window.onload = function() { document.getelementbyid("myform").onsubmit = function() { document.getelementbyid("image").src="http://mydomain.com/image?val1="+this.input1.value+"&val2="+this.input2.value; return false; }; };
you may want escape 2 values
Comments
Post a Comment