1

This seems like the most stupid question, but I cannot get this to work. I want to pass a parameter into my AJAX function from my HTML button. Code looks like:

<input type="button" onclick="signupAjax(1)" value="Sign up>

My AJAX function:

function signupAjax(int select)
{
....
//for test purposes
alert(select);
}

For whatever reason, the parameter isn't getting passed into the AJAX function. Seems pretty basic, but can't seem to get it to work.

I know there's no actual AJAX code there, the actual code works perfectly well. It would just make life easier if I could pass this parameter.

4
  • 5
    remove the int part and it should work Commented May 3, 2013 at 11:11
  • Yeah that's worked. Why don't I need to declare a type for that parameter? Commented May 3, 2013 at 11:12
  • 2
    because it is all var there isn't an int in JS just a var it is all object oriented. Commented May 3, 2013 at 11:13
  • 1
    cause its a scripting language with dynamic typing, search "dynamic typing" if you want more info about it Commented May 3, 2013 at 11:13

2 Answers 2

2

DEMO: http://jsfiddle.net/abc123/vnP4J/

Description: no need to say int select just select it is all objects in JS, next you missed a " in the input at the end.

CODE:

<script type='text/javascript'>
    function signupAjax(select)
    {
        //for test purposes
        alert(select);
    }
</script>
<input type="button" onclick="signupAjax(1)" value="Sign up" />

Notes: One this isn't AJAX nor is it ASYNC it is just an onclick event. It will be called synchronously. Inside this function some AJAX/ASYNC call could happen and it would work just fine.

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

Comments

0

The function definition should be

function signupAjax(select)
{
....
//for test purposes
alert(select);
}

Comments

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.