Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code that prints four radio buttons, has css for alignment. On Button Clic Event the buttons move towards left should stay center aligned

<html>
    <head>
        <Style type = text/css>
            .right_aligned label
            {
            float: left;
            clear: left;
            padding-right: 1em;
            text-align: right;
            }
            table.center 
            {
            margin-left:auto; 
            margin-right:auto;
            }
        </Style>
        <script src='https://code.jquery.com/jquery-1.12.4.min.js'>            
        </script>
        <script type='text/javascript'>
            $(document).ready(function()
            {$('#btnGetValue').click(function() 
            {
            var selValue = $('input[name=rbnNumber]:checked').val();
            $('p').html('<br/>You Selected : ' + selValue + '');});});
        </script>
        <script>function buttonClickHandler(){}
        </script>
    </head>
    <body>
    <table class = 'center'>
    <TR>
        <TD>Computer Science</TD>
    </TR>
    <TR>
    <TD>  
    <input type='radio' align ='' name='rbnNumber' value='You selected(a) andwhichis notthe correct answer'/>(a) and<br/>
    <input type='radio' align ='' name='rbnNumber' value='You selected(b) Todaywhichisthe correct answer'/>(b) Today<br/>
    <input type='radio' align ='' name='rbnNumber' value='You selected(c) cs whichis notthe correct answer'/>(c) cs<br/>
    <input type='radio' align ='' name='rbnNumber' value='You selected(d) os whichis notthe correct answer'/>(d) os<br/>
    </TD>
    </TR>
    <TD>    
    <p>and the results are </p>
    </TD>
    <TR>        
    </TR>
    </table>
    <table class = 'center'>
        <TR>
        <TD>
        <input type='button' id='btnGetValue' Value='Get Value'>       
        </TD>
        </TR>
    </table>        
    </body>
    </html>


What I have tried:

css, java, javascript and code
Posted
Updated 31-May-18 2:04am

1 solution

Should the result label still be centered, or aligned to the radio buttons? If centered, you could try this:

<html>
	<head>
		<script src='https://code.jquery.com/jquery-1.12.4.min.js'></script>
		<script type='text/javascript'>
			$(document).ready(function()
			{$('#btnGetValue').click(function() 
			{
			var selValue = $('input[name=rbnNumber]:checked').val();
			$('p').html('<br/>You Selected : ' + selValue + '');});});
		</script>
		<script>function buttonClickHandler(){}</script>
	</head>
	<body>
		<div style="text-align:center">
			<div style="display:inline-block;text-align:left">
				Computer Science<br/>
				<input type='radio' name='rbnNumber' value='You selected(a) andwhichis notthe correct answer'/>(a) and<br/>
				<input type='radio' name='rbnNumber' value='You selected(b) Todaywhichisthe correct answer'/>(b) Today<br/>
				<input type='radio' name='rbnNumber' value='You selected(c) cs whichis notthe correct answer'/>(c) cs<br/>
				<input type='radio' name='rbnNumber' value='You selected(d) os whichis notthe correct answer'/>(d) os<br/>
			</div>
			<p>and the results are </p>
			<input type='button' id='btnGetValue' Value='Get Value'>       
		</div>
	</body>
</html>
 
Share this answer
 
Comments
four systems 5-Jun-18 7:37am    
how does votes worc, thought should clic on star cause the answer was good

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900