cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript validation

Former Member
0 Kudos

I have 3 input fields in my htmlb:form.

When the user presses the save button, this is what I do:

<htmlb:button id = "bg1" onClientClick = "chkformelements();"

onClick = "buttonPressed" >

In my javascript function I am reading the value of each field and raising alert accordingly (if they are balnk). Problem is: even when there is an alert scenario, my onclick server event still gets fired and does what I am trying to control.

How can I control (only fire) my onclick event depending on the outcome of onclientclick event maintained by js function?

Please help.

Thanks,

Partho

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You can control the firing of onclick event by using following code:

<htmlb:button id = "bg1"

onClientClick = "var val = 'no'; val = chkformelements();if(val == 'no'){htmlbevent.cancelSubmit=true;} if(val == 'yes'){htmlbevent.verify = true;}"

onClick = "buttonPressed" >

In the function chkformelements() return 'no' if validation fails and 'yes' otherwise. htmlbevent will control the firing of onClick.

I hope it helps.

Regards,

Rohit