Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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();"
/>
share|improve this question
    
The input statement that i tried. <input type="button" value="Search" onclick="Ingredient(); | javascript: document.getElementById('_set').value='vToggle \'ON\''; Submit();" /> – user1397157 Jul 23 '12 at 21:43

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

}​
share|improve this answer
    
It works!!!!Thank you very much Bart!!!! – user1397157 Jul 23 '12 at 22:26
    
@user1397157 You're welcome! Please mark this as the 'approved answer'? Thanks! – Split Your Infinity Jul 24 '12 at 15:30
    
@user1397157 Happy with my answer? Would you like to approve my answer? – Split Your Infinity Aug 20 '12 at 13:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.