Hello, I am attempting to create a script to disable fields when the 'Status' field is = to 'Closed' I added the ifclosed to the onload portion of the page. but can't seem to get it to work. There is only one form on the page. What am I missing? Thanks David <script type="text/javascript"> function ifclosed() { with (document.forms[1]) { if (STATUS.value = "CLOSED") {document.forms[1].VEREFF.disabled=true}; {document.forms[1].CMNTS.disabled=true}; {document.forms[1].fp_submit.disabled=true}; else {document.forms[1].VEREFF.disabled=false}; {document.forms[1].CMNTS.disabled=false}; {document.forms[1].fp_submit.disabled=false}; } } </script> PHP:
Hi, I'd usually use following pattern below. Then just put whole script to the bottom of page before closing body tag </body>... <script> var myForm = document.forms[1]; if (myForm.STATUS.value = "CLOSED"){ myForm.VEREFF.setAttribute('disabled', 'disabled'); myForm.CMNTS.setAttribute('disabled', 'disabled'); myForm.fp_submit.setAttribute('disabled', 'disabled'); } else{ myForm.VEREFF.removeAttribute("disabled"); myForm.CMNTS.removeAttribute("disabled"); myForm.fp_submit.removeAttribute("disabled"); } </script> Code (JavaScript): See any errors on your Web Console? Hendra
Hello Hendra, thanks for the quick reply. I gave that a whirl and something odd is occurring. The fields are disabling, however it seems that the status is temporarily changing to CLOSED. If I remove the script, the status is back to open. I have a few test records to mess with and it happen to all of them. David
Hi David, Err, I thought you are trying to change the fields (based on status) but not the status itself; what are you actually want to achieve? And perhaps an URL link to a (test) page here may help me understand this?
I am looking to change the fields to disabled in the event that the status field has a value of 'CLOSED'. Other wise the fields are not disabled. This way a user cannot change data after the record has been 'CLOSED'. Sorry...no link. The site is internal only. David
Ah...I think I have it. I did change it a bit. <script> var myForm = document.forms[1]; if (myForm.STATUS.value != "OPEN") { myForm.DOCNO.setAttribute("readonly", true); myForm.PLANNO.setAttribute("readonly", true); myForm.STATUS.setAttribute("readonly", true); myForm.DESCR.setAttribute("readonly", true); myForm.VEREFF.setAttribute("readonly", true); myForm.CMNTS.setAttribute("readonly", true); myForm.fp_submit.setAttribute("disabled", "disabled"); } else { myForm.DOCNO.removeAttribute("readonly"); myForm.PLANNO.removeAttribute("readonly"); myForm.STATUS.removeAttribute("readonly"); myForm.DESCR.removeAttribute("readonly"); myForm.VEREFF.removeAttribute("readonly"); myForm.CMNTS.removeAttribute("readonly"); myForm.fp_submit.removeAttribute("disabled"); } </script> PHP:
Silly question on my part, but what does the FORM look like? Are these all in a consistent fieldset? If so why hardcode each and every one of these inputs instead of simply walking the DOM? also, are you sure you mean = "closed" and not == ?!? NOT that I'd be relying on array indexed .Forms since what if you re-arrange the content and/or add another form? That's why accessing by ID is your friend... Though the way this is coded it LOOKS like something that probably shouldn't even be handled client-side in the first place.
My coding is somewhat limited. I can typically get it done. At times need some assist. Nothing I create is accessed from outside the company.
I am however running into something odd. The code works in Chrome and Firefox, but not IE. However this does... <script> { document.forms[0].Shop_Order.setAttribute("readOnly", "readOnly"); document.forms[0].Shop_Order.style="background-color: #E0E0E0"; } </script> PHP: I have been trying different renditions of the readOnly attribute.
IE can be a stone cold bitch about changing the attributes on form elements. Particularly ones that control its behavior like readonly, disabled and type. Type in particular is a PITA as you basically have to clone the element and replace it on the DOM to change anything meaningful on it. It's also NOT entirely reliable on the outdated outmoded Netscape 4 style document.forms array, often failing to populate it if your form elements are dynamically created using JavaScript. That's a real head scratcher I've butted heads with more than once as it seems to work, then not work, willy-nilly with no real predictable behavior. Which is why again, I would NOT be using the document.forms array OR trying to access form elements by their name attributes in the JavaScript. Side note, if you're going to set background-color from .style, don't do the string you are overwriting any native CSS in its entirety! That's why you set style.backgroundColor="#E0E0E0"; #E0E0E0, I think I wanna know ya, know ya, woah-oh, that jungle love, yeah #E0E0E0... Did we ever mention what a pain in the ass supporting JScript (IE's clone of JavaScript that isn't QUITE JavaScript) is? Again I'd be interested to see the FORM... that way PROPER code for whatever it is you're doing could be written since without that, any scripting presented is just wild guesses and possibly outright gibberish.
I attached the page, but changed the extension to txt. It is actually asp. The page is created using FrontPage. Thanks David
Well there's your problem... Seriously, just stop. Your markup is TWO DECADES out of date, you've got endless pointless JavaScript doing HTML and CSS' job, nothing remotely resembling semantic markup, there's tables for layout, presentational markup, no doctype, an outdated incompatible character encoding... The ONLY thing you can can learn from Frontpage is how NOT to build a website. MORE so now that it's been dead and buried by its creators for nearly a DECADE. ... which confirms my suspicion, you're trying to throw JavaScript at something that has ZERO business being controlled from the JavaScript. This is NOT how you are supposed to use HTML, CSS, or JS. AT ALL. The whole mess needs to be tossed in the trash and started over -- ANYONE telling you otherwise is blowing smoke up your backside.
I getcha. Not a programmer. Only dabble. Much easier to maintain data thru a DB rather than endless paper. I knew Access and figured out how to access the DB thru FP. Because of the DB connections, I have never looked any further.
Hello DeathShadow, Hoping you you drop this here. Can you suggest an alternative to Frontpage? I also need to consider having the ability to create database connections. I am certainly open to suggestions. This is only 1% of my job here, and dealing with web issues internally is very few and far between. Thanks David