User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 363,508 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,423 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1128 | Replies: 4
Reply
Join Date: Sep 2007
Posts: 4
Reputation: srinivaskota is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
srinivaskota srinivaskota is offline Offline
Newbie Poster

How to retain the disable state of the button after page refreshing

  #1  
Sep 9th, 2007
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.
Last edited by srinivaskota : Sep 9th, 2007 at 7:45 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: srinivaskota is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
srinivaskota srinivaskota is offline Offline
Newbie Poster

Re: How to retain the disable state of the button after page refreshing

  #2  
Sep 9th, 2007
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.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,696
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 314
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: How to retain the disable state of the button after page refreshing

  #3  
Sep 9th, 2007
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.
Last edited by ~s.o.s~ : Sep 9th, 2007 at 12:33 pm.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Sep 2007
Posts: 7
Reputation: pedramphp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pedramphp pedramphp is offline Offline
Newbie Poster

Re: How to retain the disable state of the button after page refreshing

  #4  
Sep 9th, 2007
Originally Posted by srinivaskota View Post
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
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 4
Solved Threads: 45
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: How to retain the disable state of the button after page refreshing

  #5  
Sep 9th, 2007
Originally Posted by pedramphp
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.
Last edited by MattEvans : Sep 9th, 2007 at 6:20 pm.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:58 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC