0

I have a popup window that I click values from and depending on the value I want to change the value of a selection box class value in the parent window.

I have the name of the selection element but don't know how to reference the class attrib ?

window.opener.document.getElementsByName('options[911]')

Any ideas

kmas
  • 6,401
  • 13
  • 40
  • 62
  • 1
    possible duplicate of [javascript - pass selected value from popup window to parent window input box](http://stackoverflow.com/questions/9994120/javascript-pass-selected-value-from-popup-window-to-parent-window-input-box) – DoXicK May 28 '14 at 15:24
  • In addition to answers below, I suggest you also investigate the `.classList` property object. It has a number of useful member functions to manipulate classes(`.add`, `.contains`, `.remove`, `.toggle`), rather than forcing you to do your own string operations on the single string found in `.className`. – enhzflep May 28 '14 at 15:27

2 Answers2

0

The class attribute means something else than the one you need. Use className

element.className

https://developer.mozilla.org/pl/docs/DOM/element.className

Misiur
  • 5,019
  • 8
  • 38
  • 54
0

Use .className

window.opener.document.getElementsByName('options[911]').className = 'new class';

The above is not so robust.

You'll need something like this:

var elem = window.opener.document.getElementsByName('options[911]');
elem.className = elem.className.replace('oldClass','newClass');
Amit Joki
  • 58,320
  • 7
  • 77
  • 95