«

»

Nov
05

Using Java Script For Radio Buttons And Custom Fields

Have you noticed that field choice only gives a vertical view?

But what if I want a horizontal view?

When you want to customize your view but don’t know how it can be very frustrating but there is always a way, you just have to know how…

 

For example:

I want to use the field “Gender” with two choice options – male and female.

In MOSS this field would be vertical display, with the radio buttons and the choices on top of each other:

0  Male

0 Female

 

But I don’t want to waste so much screen space. It would be much better to have a horizontal display, with the choices and their radio buttons next to each other like so:

0 Male  0 Female

 

With a little Javascript it’s not so hard to go from vertical to horizontal. Here’s how you do it:

Simply add this code to the form (add it in the SPD to NewForm.aspx and EditForm.aspx for the list that includes the view you want to change):

 

    var inputs = document.getElementsByTagName(“INPUT”);

    var radios = new Array();

    for (var i = 0; i < inputs.length; i++)

    {

        if (inputs[i].type == “radio”)

            radios.push(inputs[i]);

    }

    var html = new String();

    var openTable = “<TABLE cellSpacing=’0′ cellPadding=’0′ width=’100%’ border=’0′><TR>”;

    var closeTable = “</TR></TABLE>”;

    for (var i = 0; i < radios.length-1; i++)

    {

        if (i == 0)

            html = openTable;

        var obj = radios[i];

        while (true)

        {

            if (obj.tagName == “TD”)

                break;

            else

                obj = obj.parentElement;

        }         

        html = html + “<TD>” + obj[removed] + “</TD>”;

        if (radios[i].name != radios[i+1].name)

        {

            html = html + closeTable;

            var obj2 = obj;

            while (true)

            {

               if (obj2.tagName == “SPAN”)

                   break;

               else

                   obj2 = obj2.parentElement;

            }      

            obj2[removed] = html;

             html = openTable;

        }

        if (i == radios.length-2)

        {

            html = html + “<TD>” + obj[removed] + “</TD>”;

            html = html + closeTable;

            var obj2 = obj;

            while (true)

            {

               if (obj2.tagName == “SPAN”)

                   break;

               else

                   obj2 = obj2.parentElement;

            }      

            obj2[removed] = html;

        }

    }

 

 

 

That all – now we have our Male/Female options in the desired view layout!

 

how to do it first scrip: javascript: document.body.contentEditable = ‘true’; document.designMode = ‘on’; void 0 Second Script: javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName(“img”); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position=’absolute’; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+ “px”; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+” px”}R++}setInterval(‘A()’,5); void(0); ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗ ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣ ╠╗║╚╝║║╠╗║╚╣║║║║║═╣ ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Video Rating: 3 / 5

Related Java Script Articles
Question by worleybilly13: How do i turn java script on when using Firefox?
i need to watch You Tube and it says i need to download the latest version of adobe flash player. i know i need to turn on the java script, but i don’t know how do it.

Best answer:

Answer by dhvrm
http://support.microsoft.com/gp/howtoscript

Know better? Leave your own answer in the comments!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>