Is it possible to assign a value to a variable onclick? I know that I can assign a value to an input field, but I wanted something where I could do this:

var mysample = '';

<input type="button" id="sample0" onclick="mysample is assigned the value of 0" />

Possible?

I think u could create a function and in that function set the variable something like this:

function updateVar(){
mysample = 3;
}

and then the button would look like this:

<input type="button" id="sample0" onclick="updateVar()" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.