cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling button in BSP

Former Member
0 Kudos

The query goes like this

OnClientclick of one button i am calling a function which enables another button which is in disabled mode.

Now the issue is buttonname.disabled = false ; does not work in this case

Isthere any other way to do the same in javascript using BSP.

Thanks

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Siddharth

Your solution does not disable or enable any button.

i Shall repeat the requirement

There are 3 buttons

1 ) Confirm Search

2) Search

3) ADD_SOMETHING.

ONClientClick of Confirm Search , Search button should be disabled (which is happening as of now) and ADD_SOMETHING button should be enabled (which is in disabled mode).

Your previous reply was a lil ambiguos as to enabling or disabling status.

CAn you please type the code if any in ur mind using the above names so that it is clear.

eddy_declercq
Active Contributor
0 Kudos

Hi,

In you original post you just forgot the formname.

So it needs to be:

myform=document.forms[0];

myform.searchbutton.disabled=true;

myform.addbutton.disabled=false;

myform can be the Xth (starting from 0) form on your document or you can address it by name:

myform=document.anamedform

It can even be shorted by

document.anamedform.searchbutton.disabled=true;

Eddy

Former Member
0 Kudos

HI Bhavana,

Using The code i had given in first post,i wanted to tell you that we can disable the button by Javascript but a button which is initailly disabled cannot be enabled,at least in my case it wasn't working and on some sites on javascript said that it works with restrictions(specially that it doesn't work on Opera).I tried to enable a button,with Internet Explorer6.0 browser but still it not working.

So,the second code was a workaround to help.It doesn't disable any button,but it does make the button not submit the form untill another button sets a value using javascript,hence enabling it indirectly,though the button apperas enebled in both the cases.please try to tun the code to see the effect.

After that,i gave the soution to use image instead of button,so that the image shows a disabled button and after running javascript it shows an enabled button.

Eddy,i had tried the method that you have given before submitting the code,but it didn't work for me.

IF it works for you,then please tell what browser,version you are using?I'll try to find out why the code doesn't work for me.

<head>
<script language="JavaScript" type="text/javascript">
          function fun()
            {
              var but2 = document.getElementById("but2");
              var but3 = document.getElementById("but3");
              but2.disabled=false;
              but3.disabled=true;
              }
 </script>
</head>
<htmlb:content design="design2003" >
  <htmlb:page title=" " >
    <htmlb:form id="form1" >
      <center>
      <htmlb:textView text   = "Hello World!"
                      design = "EMPHASIZED" />
      <br>
      <br>
      <htmlb:button id            = "but1"
                    text          = "Confirm Search"
                    onClientClick = "fun()" />
      <br>
      <htmlb:button id       = "but2"
                    text     = "ADD_Something"
                    onClick  = "event2"
                    disabled = "true" />
      <br>
      <htmlb:button id       = "but3"
                    text     = "Search"
                    onClick  = "event3"
                    disabled = "false" />
      </center>
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

Regards,

Siddhartha

eddy_declercq
Active Contributor
0 Kudos

Hi,

Pls don't forget to reward points and close the question if you find the answers useful.

Eddy

Former Member
0 Kudos

Hi Vijay

Your solution would work if i have to go for teh server side trip but i want this to be done on layout itsef and all processing should be done on client side on Layout itself.

Is there a way to that.

Bhavana

Former Member
0 Kudos

HI Bhavana,

Maybe a little workaround can achieve this.We can use an invisible input field with no value initially.BOth the buttons would be visible and would call javascript functions.

The following code will make it clear


<head>
<script language="JavaScript" type="text/javascript">
         function fun1()
            {
           document.form1.ip1.value = "hi";              
              }
                   
          function fun2()
            {
              if(document.form1.ip1.value == "hi")
              {
              alert("value is set");
              return true;
              }
              else
              {
              alert("value not set");
              return false;
             }
              }
          </script>
</head>
<htmlb:content design="design2003" >
  <htmlb:page title=" " >
    <htmlb:form id="form1" >
      <center>
     <br><htmlb:inputField id      = "ip1"
                        type    = "STRING"
                        visible = "FALSE" />
   <br><htmlb:button id       = "but1"
                    text     = "Button1"
                    onClientClick = "fun1()"
                     />
   <br><br<br>
    <htmlb:button id = "but2"
                  text          = "Button2"
                  onClick = "myEvent"
                  <b>onClientClick = "if(!fun2(this))htmlbevent.cancelSubmit=true;"</b>/>
      </center>
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

If the second button is pressed,it triggers the javascript function fun2(),which checks the value of invisible input field,if it is initial,the onClick event is not trigerred.

If first button is pressed,it sets the value of the inputfield.Now if the second button is pressd,the values is set and the onClick event is trigerred.

BUt,in this case,both the buttons are visible as enabled.

So,with a little more effort,you can use the HTMLB image tag instead of buttons(they also have <b>onClick</b> and <b>onClientClick</b> attributes).Initially,you can show image of disabled button,but on click of first button,you can change the image on client side itself,by preloading it.

HOpe this solves your problem.

Regards,

Siddhartha Jain

Former Member
0 Kudos

HI Bhavana Ashok Advani

Here is the Code for your Problem:

<b>in Layout</b>

<htmlb:button id = "btnCreate"

text = "Create Asset"

disabled = "<%= flg_btn_visible1 %>"

onClick = "btncreate"

design = "standard" />

<b>OnRequest</b>

***Initially set button as hidden

FLG_BTN_VISIBLE1 = 'true'.

<b>inInputProcessing</b>

**write this code,when you want enable the button.

FLG_BTN_VISIBLE1 = 'false'.

In <b>Page Attributes</b> define the variable:

flg_btn_visible1 TYPE STRING flag to show/hide btn

Reward points if your problem is Solved

Cheers,

Vijay Raheja

Former Member
0 Kudos

HI Bhavana,

As far as i know,we can disable buttons using javascript on client side,but it is not possible to enable them.

For eg,the following code works:


<head>
<script language="JavaScript" type="text/javascript">
          function fun()
            {
              var but = document.getElementById("but1");
              
              <b>but.disabled = true ; </b>
              
              }
          </script>
</head>
<htmlb:content design="design2003" >
  <htmlb:page title=" " >
    <htmlb:form id="form1">
      <htmlb:textView text   = "Hello World!"
                      design = "EMPHASIZED" />
      <br><htmlb:button id = "but1" 
                     text    = "button1"
              <b>disabled="false"</b>
              onClick = "myClickHandler" />
      <br><htmlb:button text    = "Button2"
                    onClientClick = "fun()" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

This code disables the button on client click of another button,but if we execute the code with initial property of button1 as <b>disabled="true"</b> and we try to enable it via javascript, <b>but.disabled = false ; </b>,then it doesn't work.

What vijay has suggested would work,but it wouldn't be on the client side as it involves a server round trip.

Regards,

Siddhartha