0

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();"
/>
1
  • The input statement that i tried. <input type="button" value="Search" onclick="Ingredient(); | javascript: document.getElementById('_set').value='vToggle \'ON\''; Submit();" /> Commented Jul 23, 2012 at 21:43

1 Answer 1

1

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();
    };

}​
Sign up to request clarification or add additional context in comments.

2 Comments

@user1397157 You're welcome! Please mark this as the 'approved answer'? Thanks!
@user1397157 Happy with my answer? Would you like to approve my answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.