
<form method="post" enctype="multipart/form-data">

    <div>
        <label>project</label>
        <input id="project" name="project" />
        </div>
    <div>
        <label>version</label>
        <input id="version" name="version" />
    </div>
    <div>
        <label>egg</label>
        <input id="egg" name="egg" type="file" />
    </div>
    <div>
        <input type="submit" />
        <a href="/spiders">Cancel</a>
    </div>

</form>
<script>

function extractFileName(filepath){
    filename = filepath.split('/').reverse()[0];
    filename = filename.split('\\').reverse()[0];
    return filename;
}

document.getElementById('egg').onchange = function(e) {
    console.log(e);
    console.log(e.target.value);
    filename = extractFileName(e.target.value);
    var project_name = filename.split('-')[0];
    var version = filename.split('-')[1];
    document.getElementById('project').value=project_name;
    document.getElementById('version').value=version;
};
</script>