It is hard to tell what is going on with your form when we have only a snipet of script.
Have you looked at the MDC JavaScript Reference for the documentation the slice method?
Have you added any debugging code to see what is going on?
Have you considered a different approach to the problem of getting the hirearchial name levels?
Have you looked for other post about how to do this?
var p_name = event.target.name;
var ram = p_name.slice(1,2);
console.println(ram);
I use a different approach to split the field name into an array so I can get the first tow levels of the hireachical field name.