How do I re-enable a disabled field in JS?

JavaScript and client side scripting.

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I re-enable a disabled field in JS?

Post by simonmlewis »

I have a Cart page that for some reason, is disabling the Postcode field. It's down to the theme.
So I am wondering if I use a getelementbyname, if I can disable the disabled function (if that is the cause).

To try and test it out, I am doing this, but to no avail.... trying to disable the field.

Code: Select all

  <script>document.getElementByName("wc_address_validation_postcode_lookup_postcode").disabled = true;</script>
  
  <form method='post'>
  <input type='text' name='wc_address_validation_postcode_lookup_postcode' class='input-text'>
  </form>
Any ideas?
ps we have to use Name instead of ID as the coded plugin uses Name. Not ID.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

There is no "getElementByName" function. There is a "getElementsByName", which returns a list, though.

If the problem is the theme disabling the postcode then the solution is to make the theme not disable the postcode. Adding more Javascript just makes things more complicated.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

Mmmm yes I quite agree, but where in their code, in the deep Wordpress theme, it is disabling that sort of thing, I don't know.
Trouble is, it's a third party plugin direct from Woocommerce. So something is causing it to not work. I wondered if it was an Ajax thing, but not sure.

Should this work in my test?

Code: Select all

  <script>
  document.getElementsByName("wc_address_validation_postcode_lookup_postcode")[0].disabled = false;

  </script>
  
  <form method='post'>
  <input type='text' name='wc_address_validation_postcode_lookup_postcode' class='input-text'>
  </form>
Happy to provide the plugin used, and the theme used. But would require you to have a copy of the theme to test it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

It looks like it will work, yes. Make sure you're executing that after the page has loaded, or at least that you're putting the <script> after the <form>.

To find why it's disabled, first look at when it's disabled. Does the source of the page show the field as disabled? If so then PHP code is responsible. If not then you know it is happening Javascript.
Either way you can search the plugin and/or theme code for "postcode" and see what shows up.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

This is the HTML it's rendering:

Code: Select all

		
<p class="form-row form-row-first wc-address-validation-field wc-address-validation-billing-field">
	<input type="text" class="input-text" name="wc_address_validation_postcode_lookup_postcode" placeholder="Enter Postcode" value="" />
</p>


<p class="form-row form-row-last wc-address-validation-field wc-address-validation-billing-field">
    <input type="hidden" class="wc-address-validation-address-type" value="billing" />
	<a href="#" class="button">Find Address</a>
</p>

<div class="clear"></div>

<p class="form-row message notes wc-address-validation-results wc-address-validation-field wc-address-validation-billing-field">
	<select name="wc_address_validation_postcode_lookup_postcode_results" style="width: 100%" class="wc-address-validation-enhanced-select select billing"></select>
</p>

<hr/>

<p class="form-row form-row-first wc-address-validation-field wc-address-validation-shipping-field">
	<input type="text" class="input-text" name="wc_address_validation_postcode_lookup_postcode" placeholder="Enter Postcode" value="" />
</p>


<p class="form-row form-row-last wc-address-validation-field wc-address-validation-shipping-field">
    <input type="hidden" class="wc-address-validation-address-type" value="shipping" />
	<a href="#" class="button">Find Address</a>
</p>

<div class="clear"></div>

<p class="form-row message notes wc-address-validation-results wc-address-validation-field wc-address-validation-shipping-field">
	<select name="wc_address_validation_postcode_lookup_postcode_results" style="width: 100%" class="wc-address-validation-enhanced-select select shipping"></select>
</p>
And this does in fact appear at the bottom of the page:

Code: Select all

<script type='text/javascript'> 
  
  document.getElementsByName("wc_address_validation_postcode_lookup_postcode")[0].disabled = false;</script>
But it isn't enabling the form field for Postcode.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

Are you sure the field is actually disabled? Does the DOM say it's disabled, like

Code: Select all

alert(document.getElementsByName("wc_address_validation_postcode_lookup_postcode")[0].disabled); // true?
or is there some other mechanism in effect?

Again, find out what the theme/plugin is doing.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

That generates a popup that says "false". What does that mean?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

Means it's not actually disabled.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

Mmmmm damn it. So is there any way of finding out what is causing it to (I use this term cautiously) ... be disabled? Or readonly.
I suppose there is the chance that the Theme just has some sort of conflict with it.

Do you know of any other Wordpress Plugins that do Post/Zipcode lookups? Enter code, choose address from dropdown etc.
Surely there isn't just the one out there. Tho it is by WooCommerce. lol.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

simonmlewis wrote:So is there any way of finding out what is causing it to (I use this term cautiously) ... be disabled? Or readonly.
I'll say it one more time before I give up:

Look at the theme or plugin, whichever you're talking about as being the source of the problem, to see how and why it is "disabling" the field. Then you can react accordingly.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

I'll give up too. Absolutely no way of finding out. Without asking theme developers. Who are vague.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

Is the source code obfuscated?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

No, the code is all there, but the cause to the problem could among any one of all the files in the folder structure.
Finding out which one it is, is likely to be impossible.

We should be getting some theme issues sorted next week, and the theme people may be able to help.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I re-enable a disabled field in JS?

Post by requinix »

simonmlewis wrote:Finding out which one it is, is likely to be impossible.
Not even remotely the case, but it's clear you don't even want to try so whatever.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I re-enable a disabled field in JS?

Post by simonmlewis »

How on earth do I "try", when it i Wordpress, and is full of JS and CSS and all sorts of included PHP files from all over.
I just would not know where to start.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply