0

I am using this java script to change the input type for a field, it doesn't seem to work. please help

 <script type="text/javascript" charset="UTF-8" language="JavaScript">{literal}
    addLoadEvent(function () {
    document.getElementById(“form1").attributes["type"] = "text";
     }
    );
    {/literal}</script>
1
  • Note that changing the type of an input is not supported in all browsers (older IE versions). Commented Feb 23, 2014 at 2:12

2 Answers 2

2

Be sure that you are using the correct ASCII characters in your code. It appears that:

getElementById(“form1")

should infact be:

getElementById("form1")

Note the different first quotation character.

Another note: I'm not sure what {literal} and {/literal} are, but if they are actually in your code, you should also try removing those if you continue to have problems.

Sign up to request clarification or add additional context in comments.

Comments

1

Try:

 addLoadEvent(function () {
     document.getElementById("form1").setAttribute("type", "text");
 });

As Ryan pointed out, “form1" needs to be change to "form1". Also, attributes[] can cause some browser incompatibilities. See here

3 Comments

Why should the OP try that? What's wrong with their code?
“form1" to "form1". Also, attributes[] can cause some browser incompatibilities. See here
Best edit your answer and add this information. Also note that the problems with attributes don't apply in this case. The OP doesn't try to access the style attribute, nor is the attribute name uppercase.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.