Thursday, April 14, 2005

Javascript Button Disabled

Question: I have a form whose fields are populated by a dropdown called "layoutlist". There is also a button called "reportsubmit". Now if you choose a report and click the "reportsubmit" button BEFORE the page has loaded, you get an output of the PREVIOUS report you chose. So what I want to do is disable the button as soon as you make a choice in "layoutlist." Then I want to enable it once the page has completely loaded.

I've tried an inline script right after the form field:
<script>
document.rptform.reportsubmit.disabled = true;
</script>

Then at the end of the page:
<cfif isDefined("form.layoutlist") and form.layoutlist IS NOT "NONE">
<script>
for (i=1; i<=1000000; i=i+1)
{
}
document.rptform.reportsubmit.disabled = false;
</script>
</cfif>

Which works great the first time you come to the page. However, once you are there and the button is enabled, choosing another layout doesn't disable the "reportsubmit" button right away.

Answer:
<select name="layoutlist" OnChange="formSubmit('null');"
onFocus="rptform.reportsubmit.disabled=true;">
--the "onFocus" part is what I added

<input type="button" name="reportsubmit" value="Excel Output"
onClick="formSubmit('reportsubmit');" />
--this is the button to disable

Immediately disables the reportsubmit button when I click on "layoutlist". But why does the reportsubmit button re-enable itself once the page is loaded? I am so glad that it does! Can anyone explain to me why?

0 Comments:

Post a Comment

<< Home