I was trying to get selected radio button by using \"document.getElementByName(\'nameOfradio\')\" because all of the radio buttons share the same name. But, nothing happened
This is exactly why you should use a javascript library.
document.querySelector('input[name=nameOfradio]');
for example is not supported before IE8.
Let the library handle the browser craziness.
In jQuery you can just use $('input[name=radioName]:checked').val() or $("form").serialize() and be done with it.