Tyler February 2016

Targeting document.getElementById to sub templates?

I cannot get certain fields in a form to unlock. I have a javascript file that works on certain pages, but not on others.

I am using document.getElementById to target form fields to disable or enable them depending on certain inputs. It works fine on one page but not another. I have double checked all my ids and they are correct. Here is the javascript:

var pass2 = document.getElementById("password").value;
     if (pass1 == pass2) {

            //start profile
            document.getElementById("premium-text").innerHTML = "Congratulations! You have unlocked the premium fields!";
            document.getElementById("premium").style.background = "#d1fdd3";
            document.getElementById("premium").style.borderColor = "#019408";
             document.getElementById("description").disabled = false; 
             document.getElementById("fax-number").disabled = false;
             document.getElementById("facebook-url").disabled = false;
             document.getElementById("twitter-url").disabled = false;
             document.getElementById("google-plus-url").disabled = false;
             document.getElementById("linkedin-url").disabled = false;
             document.getElementById("type").disabled = false;
             document.getElementById("city").disabled = false;
             document.getElementById("status").disabled = false;
             document.getElementById("price").disabled = false;
             document.getElementById("bedrooms").disabled = false;
             document.getElementById("bathrooms").disabled = false;
             document.getElementById("size").disabled = false;
             document.getElementById("property-id").disabled = false;
             document.getElementById("video-url").disabled = false;
             document.getElementById("featured").disabled = false;

The only difference in the pages is one has the form fields in the template (form ids are directly in edit-

Answers


Arun Sharma February 2016

Make sure you don't have same multiple ids. If you can post your code I'll be able to assist you better.


Tyler February 2016

I split the Javascript into two seperate files and that seemed to work. I can only assume this had something to do with the fact that there were different field ids on each page and when the document.getElementById ran and didn't find all the ids (since some were on a different page) that is why it wasn't working.

Post Status

Asked in February 2016
Viewed 1,487 times
Voted 7
Answered 2 times

Search




Leave an answer