bowemc
asked on
Simple detection of button clicked
Hi,
I'm running a javascript when <form id=onSubmit="return chk()">. What i want to do is detect which button has been clicked to cause the submit action. If its "ImageButton1" return true else if its "ImageButton2" contine and persom the rest of chk() whci is as below.
Thanks
function chk() {
var val=document.getElementByI d("lblTota l").innerH TML;
var realVal=val.replace(/[b\<\ >\€\/]/g," ");
var len = realVal.length;
var val1 = realVal.substring(1,len);
var val2 = parseFloat(val1);
if(val2>=25) {
return true;
}
else {
alert("You cannot proceed as your balance is less than E25.00. \nPlease select additional items before trying to proceed again. Thank you.");
return false
}
}
I'm running a javascript when <form id=onSubmit="return chk()">. What i want to do is detect which button has been clicked to cause the submit action. If its "ImageButton1" return true else if its "ImageButton2" contine and persom the rest of chk() whci is as below.
Thanks
function chk() {
var val=document.getElementByI
var realVal=val.replace(/[b\<\
var len = realVal.length;
var val1 = realVal.substring(1,len);
var val2 = parseFloat(val1);
if(val2>=25) {
return true;
}
else {
alert("You cannot proceed as your balance is less than E25.00. \nPlease select additional items before trying to proceed again. Thank you.");
return false
}
}
ASKER
ok to clarify i have:
<asp:imagebutton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end _site_imag es/proceed _checkout. gif" width="66"></asp:imagebutt on>
when this (or currently any button is clicked on the form the following line is called:
<form id=Form1 onSubmit="return chk()" method=post runat="server"> ------> onSubmit="return chk()"
which in turns calls the method i posted at the start....
I tried what you sugggested by entering
onSubmit="return chk(event)" and addint the first two lines suggested in the chk() metod ---- when i ran it in Firefox nothing happened - it was like chk() never got called - no msg box appeared
any ideas?
<asp:imagebutton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end
when this (or currently any button is clicked on the form the following line is called:
<form id=Form1 onSubmit="return chk()" method=post runat="server"> ------> onSubmit="return chk()"
which in turns calls the method i posted at the start....
I tried what you sugggested by entering
onSubmit="return chk(event)" and addint the first two lines suggested in the chk() metod ---- when i ran it in Firefox nothing happened - it was like chk() never got called - no msg box appeared
any ideas?
I can sort of see that there is a problem since the event that is being executed during chk is onsubmit which doesn't have a target element. The workaround would be to have each button call the chk function and submit the form and remove it from the onsubmit altogether.
ASKER
how do i call chk() on the click event of just
<asp:imagebutton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end _site_imag es/proceed _checkout. gif" width="66"></asp:imagebutt on>
wouldn't this not work (obviously just from what you know of my application!) ... thanks again
<asp:imagebutton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end
wouldn't this not work (obviously just from what you know of my application!) ... thanks again
As far as I know this does work. Let me know if I am wrong.
<asp:imagebutton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end _site_imag es/proceed _checkout. gif" width="66" onclick="chk(event);"></as p:imagebut ton>
<asp:imagebutton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end
ASKER
Error!!
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1513: } expected
Source Error:
Line 321:<tr><td> </td><td ><center>< asp:imageb utton id="ImageButton2" Runat="server" height="15" border="0" ImageUrl="images/front_end _site_imag es/proceed _checkout. gif" width="66" onclick="chk(event);"></as p:imagebut ton></cent er></td></ tr>
Any more ideas? All welcome!!
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1513: } expected
Source Error:
Line 321:<tr><td> </td><td
Any more ideas? All welcome!!
I guess I am not so great with the asp stuff.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the line clickId = e ? e.target : window.event.srcElement;
the javascript module in firefox complians that e is not defined - which i think is true - what is e and where should i declare it?
thanks
the javascript module in firefox complians that e is not defined - which i think is true - what is e and where should i declare it?
thanks
function chk(e) {
var elem = e ? e.target : window.event.srcElement;
alert(elem.name + " " + elem.id);
var val=document.getElementByI
var realVal=val.replace(/[b\<\
var len = realVal.length;
var val1 = realVal.substring(1,len);
var val2 = parseFloat(val1);
if(val2>=25) {
return true;
}
else {
alert("You cannot proceed as your balance is less than E25.00. \nPlease select additional items before trying to proceed again. Thank you.");
return false
}
}