cancel
Showing results for 
Search instead for 
Did you mean: 

onClientClick Help

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

athavanraja
Active Contributor
0 Kudos

hi Jon,

I found out about this from HTMLB_SAMPLES/radiobuttongroupSample.htm .

Vara has solved your problem, why dont you mark this thread as answered and assign some points to Vara.

Regards

Raja

Answers (2)

Answers (2)

daniel_humberg
Contributor
0 Kudos

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.

maximilian_schaufler
Active Contributor
0 Kudos

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.

daniel_humberg
Contributor
0 Kudos

Hi Maximilian,

thx for the hint. but what about "onClick="myEvent""?

sometimes i use "myEvent" in do_handle_event to check which event has been fired. what will this "onclick"-value be with your solution?

maximilian_schaufler
Active Contributor
0 Kudos

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.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You might have a look at the following posting from a while back: