cancel
Showing results for 
Search instead for 
Did you mean: 

how to Disable default button

Former Member
0 Kudos

Hi all

I am running on EP 6 SP 9

I have a JSPDynPage with a HTMLB form which has a default button set using the defaultButton attribute of the form

<hbj:button

id="OKButton"

text="<%= localString %>"

width="70"

design="EMPHASIZED"

onClick="Search"

onClientClick="dounload();disableControl(this)"

>

<%

searchForm.setDefaultButton(OKButton);

%>

</hbj:button>

now in the disableControl method I need to disable the button OKButton.

the following js fuction does exactly that, the button is grayed out and cannot be clicked with the mouse

function disableControl(control){

control.setDisabled();

}

however if I press Enter key the form apparently attempts to invoke the eventhandler for this button, this throws a js error: Object doesn't support this property or method

the funny thing is that the line(18) this error occurs on does not contain any js code.

Has anyone had this same problem or is there another way to change the forms default button using js?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Ulrik,

In order to prevent the event handler from being called,

you can use htmlb.cancelsubmit = true;

in your javascript.

(Please award points for a useful answer).

Regards,

Harish

Former Member
0 Kudos

Hi,

>>if I press Enter key the form apparently attempts to invoke the eventhandler for this button

If a button is set to be default, and when you press enter key or return key , the default button's onClick() event will be fired.

In disableControl method, add the following line

searchForm.setDefaultButton(null);

This sets the default button to be none. Hope this helps to solve the problem.

Regards,

Uma

Message was edited by: Uma Maheswari

Former Member
0 Kudos

>>Uma

I already tried this.

serchForm is undefined in js

adding the line as server side code in the js doesnt work either

<%

searchForm.setDefaultButton(null);

%>

I also tried to get the form from the control this way in disableControl js function

function disableControl(control){

control.setDisabled();

var jsForm = control.form;

jsForm.setDefaultButton(null);

}

jsForm is undefined in the last line

does anyone know how to get a reference to the HTMLB form of the page using javascript?

former_member184154
Active Contributor
0 Kudos

Ok, try disabling the enter button redirecting its function to do nothing.

Have a look <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/11802">here</a> for how to handle keyboard events.

I did the same story once on a prj 'cause users of my webapp were used to SAPGui (where most of the times enter=refresh) and they accidentally were hitting enter causing the form to submit, so I disabled it.

Hope this helps. Let me know.

Alex

former_member184154
Active Contributor
0 Kudos

My experience with EP is that you should try to avoid JS as much as possible, as EP has its own tons of JS, and consistently putting your own stuff in there it's a hard job.

In matching ABAP bsp object (htmlb button) there's a "Disabled" property, controlled on server side. There should be an equivalent in your case.

Alex

Former Member
0 Kudos

>>Alessandro

I have disabled the button using the js I posted here, that is not the problem the problem is that the form still attempts to "press" the button when the user presses enter, this gives an error excactly because I disabled the button