on 11-30-2004 3:46 PM
Hello,
Does anyone know if onClientClick can control onClick? For example, I would like to use onClientClick to do my javascript form validation and if an error occurs, I do not want onClick to process - however, if no errors occr, I want the program to proceed with the onClick functionality.
If this is not possible, all other recommendations would be appreciated.
Thanks,
Jon
HI...
YOu can do it using the Javascript programming.
Please find the below code.
<htmlb:document>
<htmlb:documentHead>
<script language="javascript">
function chkInput(){
alert("Java Script Fired");
if(document.mainform.FILE1.value == ""){
alert();
return false;
}
else
{
return true;
}
}
</script>
</htmlb:documentHead>
<htmlb:documentBody>
<htmlb:form id="mainform" >
<htmlb:textView id = "Lab"
text = "Local File Path" />
<htmlb:fileUpload id = "FILE1"
size = "20"
maxLength = "100" />
<htmlb:button id = "BUT1"
onClick = "CHK"
<b>onClientClick = "if(!chkInput())htmlbevent.cancelSubmit = true;;"</b>
text = "Click Here" />
</htmlb:form>
</htmlb:documentBody>
</htmlb:document>
-
The above is working fine. Whenever the onClientClick is triggered, the Javascript function chkInput(); is triggered. THis function returns a boolean value. If the returned value is false then the HTMLB event is cancelled.
I hope it solves your purpose.
Thanks & Regards,
Vara
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vara,
Thanks for the help - it worked perfectly (as did the other but his was easiest to implement). I'm just wondering how you knew htmlbevent.cancelSubmit = true existed? I searched through a lot of documentation and couldn't find anything like this. Is there a "class" or "event listing" that will show all of the attributes of something like htmlbevent?
Thanks in advance,
Jon
For this, I usually use 2 buttons, while the one is invisible.
<script language="javascript">
function check_and_click(){
if(..validate you fields..){
var btn = document.getElementById("b2");
if(var){
btn.click();
}
}
}
</script>
<htmlb:button id="b1" text="click me" onClientClick="check_and_click();"/>
<div style="display:none;">
<htmlb:button id="b2" text=".." onClick="myEvent"/>
</div>
havn't tested this code, so check for typing errors etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
you seem to have a knack for invisible elements
If you use this code in onClientClick of your button b2, you don't need to make it invisible or add the additional button:
htmlbevent.cancelSubmit = !formCheck();
The function formCheck() is then responsible for returning true if all checks are passed, or false if the form submit is to be canceled.
Just use the onClick as you are used to, your button now holds both attributes, onClick as well as onClientClick.
Set onClick to the event you want to handle in do_handle_event, and additionally use the onClientClick attribute to do some javascript-checks whether button should submit the form or not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.