1

The aim is that when the page is loaded, an onload call to a function will be made and inside this function will be an input type which will access a devices camera.

How can i call an input type inside a JavaScript function?

    <!DOCTYPE HTML>
<html>
<head>
<title>Take Picture</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />

<script type="text/javascript">

    function getPic()
    {
        <input type="file" id="takePic" style="display: none;" accept="image/*;capture=camera">
    }
</script>  

</head>

<body onload="getPic()">

EDIT : The line of code below allows access to the device's camera, which works fine.

<input type="file" id="takePic" accept="image/*;capture=camera">

basically what i want is, when the page loads, it automatically clicks the choose file button from the above piece of code. I assumed the best way to do this was by JS. I may be wrong.

I have very little knowledge of JS so i came here for help after finding little on the net.

user1081326
  • 415
  • 5
  • 10
  • 19

2 Answers2

0

If you want to add input in body use document.write

function getPic()
{
    document.write('<input type="file" id="takePic" style="display: none;" accept="image/*;capture=camera">');
}

If you want to access that input use getElementById().

document.getElementById('takePic')
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
0

If your goal is taking a snapshot from a webcam, you might be better off using the navigator.getUserMedia() API.

See this page for details: http://www.html5rocks.com/en/tutorials/getusermedia/intro/

It's unsupported in IE and Safari, but works in current versions of Firefox, Chrome and Opera: http://caniuse.com/#feat=stream

Jakob Kruse
  • 2,458
  • 18
  • 17