JQuery to fill in an input or text field

<div id="example"></div>
  <script type="text/javascript">
             jah = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
             jah+= "<p>Browser Name: " + navigator.appName + "</p>";
             jah+= "<p>Browser Version: " + navigator.appVersion + "</p>";
             jah+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
             jah+= "<p>Platform: " + navigator.platform + "</p>";
             jah+= "<p>User-agent header: " + navigator.userAgent + "</p>";

             document.getElementById("example").innerHTML=jah;

             </script>

I use the code above to compile some browser information that I need to collect from a form. How can I get this information passed to Input or Textarea?

Thanks in advance!

+5
source share
4 answers

If you want to use pure JavaScript instead of jQuery, try the following:

<form><textarea id="ta"></textarea></form>
<script type="text/javascript">
    jah = "whatever you want";
    var ta = document.getElementById('ta');
    ta.value = jah;
</script>

Assignment .valueto jQuery Function.val(v);

+2
source

Using $.val. Assuming it #exampleis a selector pointing to the corresponding input field, you can use something like this:

$('#example').val(jah);
+14
source

, jQuery val method $('#Id').val(jah);

Where Id is the input identifier for the text field. :)

+2
source
$('#myinput').val($('#example').find('p').text());

where "myinput" is the identifier of your text field. Insert this line after

document.getElementById("example").innerHTML=jah;
0
source

All Articles