简体   繁体   中英

Passing multiple parameters and a javascript function in input button

I want to pass several parameters and a javascript function in a button.

I have to pass a parameter vToggle and the value is ON and a javascript function Ingredient() .

I tried like this:

<input type="button" value="Search" onclick=
    "Ingredient(); |
    javascript: document.getElementById('_set').value='vToggle \'ON\'';
    Submit();"
/>

You should be able to do it like this .

JavaScript

function buttonClick() {
    Ingredient();
    document.getElementById('_set').value='vToggle \'ON\'';
    Submit();
};​

HTML

<button onclick="javascript: buttonClick();">Click me</button>​

But be aware that you load the script that creates the function before the button loads. If you don't want to load your function before the button is loaded you need to delay the binding to the click event. See this Fiddle for a demo.

HTML

<button id="ingredientButton">Click me</button>​

JavaScript

document.onreadystatechange = function() {

    document.getElementById("ingredientButton").onclick = function() {
        Ingredient();
        document.getElementById('_set').value='vToggle \'ON\'';
        Submit();
    };

}​

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