-1

I'm a newbie to JQuery. I'm trying to add "input" tag to form in different select case.

  $(document).ready(function() {
        $("select[name=InputSource]").change(function() {
            if (this.value == 3) {
                eth_input = true;
                $(".page_ip").attr("form", "broadcastform");
            } else {
                eth_input = false;
                $(".page_ip").attr("form", "");
            }
        });
    });

But attr seems not working for IE. I search for article that people suggest to use data-* with IE browser. But problem is that I still need to change "form" attribute in order to make this input into the form. Is there anyway to apply attr to change "form" attribute?

Pwan
  • 153
  • 13
  • yes. In chrome and firefox, it works fine. but in IE, I check the console there is nothing change. – Pwan Aug 29 '16 at 03:57
  • put in code in fiddle .. – Sumit patel Aug 29 '16 at 03:59
  • @Pwan: We can't answer your question without more context. I suggest creating a **runnable** [mcve] using Stack Snippets (the `<>` toolbar button). `attr` should work with the [`form` attribute](https://www.w3.org/TR/html5/forms.html#attr-fae-form). – T.J. Crowder Aug 29 '16 at 04:02
  • @Pwan: My mistake, we can: This is probably a duplicate of [*Internet Explorer issue with HTML5 form attribute for button element*](http://stackoverflow.com/questions/20658402/internet-explorer-issue-with-html5-form-attribute-for-button-element) - IE doesn't support the `form` attribute. – T.J. Crowder Aug 29 '16 at 04:09

3 Answers3

3

It's not that the form attribute isn't being applied by your code. It's that IE doesn't support it (not even IE11). Details and possible workaround in this question and its answers (and other questions and their answers linked to it).

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

You can use the javascript setAttribute instead Jquery. See the support here: http://caniuse.com/#search=setAttribute Add:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

along with <!DOCTYPE html>

It works in IE8+ environments

ajaykumar
  • 646
  • 7
  • 17
0

Its because form attribute is part of HTML5 and is not supported by IE. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input.

This had hppened with me when I tried to add/change few ARIA attrs which are not supported by IE. Though form attr's usage can be ignored by wrapping up in a separate form and appended after the previous form. And position it at desired place.

Your code snippet is not helping very much as the markup/html is also required to suggest better solution.

Pankaj
  • 954
  • 8
  • 15