Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2006, 03:05 PM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with dynamically rendered radio buttons

I'm trying to dynamically render radio buttons. Here is my test code...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
    function writeRadio () {

        var sp = document.getElementById("filterRow");
        sp.appendChild(document.createTextNode("Pick me "));

        var input = document.createElement("input");
        input.type="radio";
        input.name ="myradiobutton";
        input.defaultValue = "value1"

        sp.appendChild(input);
        sp.appendChild(document.createTextNode(" or me "));

        input = document.createElement("input");
        input.type="radio";
        input.name ="myradiobutton";
        input.value = "value2";

        sp.appendChild(input);
    }
</script>
</head>

<body onLoad="writeRadio();">
<form name="bob">
<p id="filterRow"></p>
</form>
</body>
</html>

When rendered on the page, the radio buttons work fine in mozilla (Firefox) but will not select when clicked in Internet Explorer.

Any ideas would be greatly appreciated!

 
Old January 19th, 2006, 04:41 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Daddyunit!!
Solution is below
 I have checked this code in IE,working fine.
 Let me know if not working in FireFox


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
    function writeRadio () {

        var sp = document.getElementById("filterRow");
        sp.appendChild(document.createTextNode("Pick me1 "));

        var input = document.createElement("input");
        input.type="radio";
        input.name ="myradiobutton";
        input.defaultValue = "value1"
        input.id ="myradiobutton";
        input.onclick = function() { enableRadio('1') };

        sp.appendChild(input);
        sp.appendChild(document.createTextNode(" or me2 "));

        input = document.createElement("input");
        input.type="radio";
        input.name ="myradiobutton";
        input.id ="myradiobutton";
        input.value = "value2";
        input.onclick = function() { enableRadio('2') };
        sp.appendChild(input);


    sp.appendChild(document.createTextNode(" or me3 "));

        input = document.createElement("input");
        input.type="radio";
        input.name ="myradiobutton";
        input.id ="myradiobutton";
        input.value = "value2";
        input.onclick = function() { enableRadio('3') };
        sp.appendChild(input);
    }

function enableRadio(objlocation)
{

disableAllRadio();

var sp = eval('document.bob.myradiobutton');
sp[objlocation-1].checked=true

}

function disableAllRadio()
{
var sp = eval('document.bob.myradiobutton');

for(i=0;i<=sp.length-1;i++)
 {
 sp[i].checked=false
 }

}
</script>
</head>

<body onLoad="writeRadio();">
<form name="bob">
<p id="filterRow"></p>
</form>
</body>
</html>

Hope this will help you


Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
validation in radio buttons MunishBhatia ASP.NET 2.0 Professional 5 December 11th, 2007 11:15 AM
Validation Radio Buttons jonsey Classic ASP Professional 1 June 6th, 2007 11:48 PM
Dynamically added panel with radio buttons ADM10 Visual Basic 2005 Basics 1 May 11th, 2006 10:27 PM
How to use the radio buttons? ben_VB VB.NET 2002/2003 Basics 1 January 18th, 2005 12:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.