Hi Experts here,
Pls help.

when I disable the button using the code

document.getElementById("mybutton").disable=true;

it is disabling perfectly but when the page gets refreshed again it comes
to enable position

so, I need a code even when the refreshing the page also my button is in disable position.
Thanks and Regards,
Srinivas yadav.

Hi Experts here,
Pls help.
when I disable the button using the code

document.getElementById("mybutton").disable=true;

it is disabling perfectly but when the page gets refreshed again it comes
to enable position

so, I need a code even when the refreshing the page also my button is in disable position.
Thanks and Regards,
Srinivas yadav.

Use the 'onload' event handler for this task. This way, as soon as the document / body is loaded, the button will be in disabled state.

<html>
<head></head>
<body onload="funcToDisable();">
</body>
</html>

Here the 'functionToDisable()' will contain the action which you need to perform when the document loads.

That all being said, you should realize that the HTTP is a stateless protocol so you can't keep the button enabled on the first try and disabled on all consecutive reloads since there is way of knowing it. Your best bet would be to keep a flag at the server which will keep track whether its the users' first visit or not and act accordingly.

Hi Experts here,
Pls help.

when I disable the button using the code

document.getElementById("mybutton").disable=true;

it is disabling perfectly but when the page gets refreshed again it comes
to enable position

so, I need a code even when the refreshing the page also my button is in disable position.
Thanks and Regards,
Srinivas yadav.

you have to do like this...
because you have made the input button after the head tag you can not use the script in the head so you have to write the code after the input button , another problem you had you have to use disabled instead of disable
<html>
<head><head>
<body>
<input type="button" name="mybutton" value="mybutton">
<script language="javascruipt>
document.getElementById("mybutton").disabled=true;
</script>
</body>
</html>

best REgards Pedram
Pedramphp@gmail.com

because you have made the input button after the head tag you can not use the script in the head so you have to write the code after the input button , another problem you had you have to use disabled instead of disable

Or use the body onload handler as sos suggested.. It makes for a more manageable project if you use onload to call one onload function that does all one-time-only functions, rather than putting bits of script inbetween html elements..

To srinivaskota, if you have some condition that must be met to enable the button; and the condition is usually not yet met when the page is first accessed ( or refreshed ), i.e. the button should only become enabled as the result of some javascript code; set the button as disabled in the HTML, i.e.

<button disabled="true" >Button Text</button>

Then, when the condition is met, set the element's disabled property to false. You'll still probably need an onload handler to check if the condition is met, if it's some kind of persistant condition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.