Skip to Content
author's profile photo Former Member
Former Member

onClientClick Help

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 01, 2004 at 01:17 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 30, 2004 at 03:54 PM

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

    simulation-of-button-push-via-javascript-in-htmlb-

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 01, 2004 at 08:05 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.