简体   繁体   中英

Passing information using the DOM between HTML files and linked .js files.

Can someone tell me or show me how to pass information from a HTML page to a linked .js file?

<head>
<script type="text/javascript" src="../javascripts/script.js"></script>
</head>

<form name="form1">
    <input type="text" name="input1" value autofocus="on">
    <button onClick= "chrome.tabs.create({url: getURL()});">Go</button>
</form>

This is part of a form I want to be completed, and the input value taken, combined with a pre-existing URL, and the end result opened in a new tab

function getURL()
{
    var site = "http://www.example.com/query?f=";
    var input = document.form1.input1.value
    var output = site + input;
    return output;
}

This is the function I'll be using, but I can't work out or don't know yet how to link the input variable to the input1 form value. The .js file is linked, rather than inside the actual HTML file.

Help?

Elements with their IDs or names automatically mapped to hierarchically-organised properties under document , as in document.name1.name2 , is a long-deprecated practice and doesn't occur unless your document triggers quirks mode. Add an ID to the input element then use

var input = document.getElementById('input_id_goes_here').value;

instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM