/    Sign up×
Community /Pin to ProfileBookmark

how to know which of the 2 buttons are clicked

hi there,

how will i know which of the 2 buttons are clicked. i tried using
var flag = document.frmMain.btnSave.Clicked;
and printing the value of flag to know. but it turns out to be null.

can anyone help me out here please..

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallFeb 01.2008 — If each button has the same name and a different value then test which value is assigned eg.

<input type="button" name="mybutton" value="button1">

<input type="button" name="mybutton" value="button2">

then the value in mybutton.value will be the value of the button that was clicked.
Copy linkTweet thisAlerts:
@rejoy_studauthorFeb 01.2008 — nope its got 2 different names as well.

but how can we know which one is clicked

document.frmMain.btnSave.value will always give the value 'Save' right
Copy linkTweet thisAlerts:
@fpmarinFeb 06.2008 — Example:

<!--xhtml code-->

<form id="f">

<input type="button" />

<input type="button" />

<input type="button" />

</form>

// javascript code

function buttonIndex()

{

var i=0;

while ( i<B.length ) {

if ( this===B[i] ) break; // Note the "three = symbol": ===. Very important

++i;

}



if ( i==0 ) /* do something with the first button */;
else if ( i==1 ) /* ... second button */;

else /* ... third button */;

}

window.onload
=


function()

{

B=document.getElementById("f");

B=B.getElementsByTagName("input");

var i=0;

while ( i<B.length ) B[i++].onclick=buttonIndex;

}
×

Success!

Help @rejoy_stud spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...