Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkbox not showing

    Hi, I have the following codes but my checkbox is not appearing. The values of the checkbox do print out in the alert. Can anyone tell me what is wrong with it? Thank you!

    Code:
     var table = document.getElementById('maintable');
            var i;  // iterator
            var item; // pointer to item in received list
            for(i = 0; 
                (item = contacts.ReturnValue.getNext()) != undefined; 
                ++i) {
                table.insertRow(i + 1);
                var result = "<td>";
                if(item.FirstName != undefined) {
                    result += item.FirstName.Value;
                }
                result += "</td><td>";
                if(item.LastName != undefined) {
                    result += item.LastName.Value;
                }
                result += "</td><td>";
                if(item.MobilePhoneGen != undefined) {
                    result += item.MobilePhoneGen.Value;
                }
                result += "</td><td>";
                if(item.EmailGen != undefined) {
                    result += item.EmailGen.Value;
                }
    			
    			var td1 = document.createElement("td");
    			var chkbox = document.createElement('input');
    			chkbox.type='Checkbox';
    
    			table.rows[i + 1].innerHTML = result;
    			chkbox.value=item.MobilePhoneGen.Value;
    			td1.appendChild(chkbox);
    			alert(chkbox.value);	
            }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Your HTML is illegal. You may not have a checkbox within a <td>.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so how should i do?

  • #4
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i change it to the following codes the checkboxes came out but the value is empty for the second checkbox.

    Code:
    result += "<input type=checkbox name=chkbox>";
    			
    			result += "</td>";
    			
    			table.rows[i + 1].innerHTML = result;
    			document.contact.chkbox.value = item.MobilePhoneGen.Value;
    			alert(document.contact.chkbox.value);
    i need to run my codes in a nokia phone. basically it's is getting all the contact from the phonebook and display it. everything show except the checkbox.
    Last edited by wenn; 12-22-2010 at 08:46 AM.

  • #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    I just validated a checkbox within a td and in any case it would still show.

    Due To I.E., form element creation is a bit more involved than with other elements.

    Can you confirm there are no console errors?

    Can you host a live demo?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Logic Ali View Post
    I just validated a checkbox within a td and in any case it would still show.
    Oh, you are quite right! Sorry - brain hit a bad sector!


    Try this which works in IE:-

    Code:
    <html>
    <head>
    <script type = "text/javascript">
    
    function addNewRow(theTable){
    index = theTable.rows.length;
    nextRow =  theTable.insertRow(index);
    chkBox = nextRow.insertCell(0);
    txtBox1 = nextRow.insertCell(1);
    txtBox2 = nextRow.insertCell(2);
    index++;
    chkBox.innerHTML = "CheckBox "+index+ " <input type=checkbox name='cbox'+index>"; 
    indexN = (index*2)-1;
    txtBox1.innerHTML = "TextBox "+indexN+ " <input type= text name ='tbx"+indexN+"'>";
    indexN++;
    txtBox2.innerHTML = "TextBox "+indexN+ " <input type=text name='tbx"+indexN+"'>";
    }
    
    </script>
    </head>
    <body>
    <center>
    <form name= "myform">
    <table id= "myTable" cellpadding=5 cellspacing=5 border=1></table>
    </form>
    <br>
    <input type=button value="Insert New Row" onclick="addNewRow(myTable)"><br>
    </body>
    </html>
    Create the table, then populate it. e.g. document.myform.tbx2.value = "Whatever";
    Last edited by Philip M; 12-22-2010 at 09:40 AM.

  • #7
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Logic Ali View Post
    I just validated a checkbox within a td and in any case it would still show.

    Due To I.E., form element creation is a bit more involved than with other elements.

    Can you confirm there are no console errors?

    Can you host a live demo?
    i need to run my codes in a nokia phone. basically it's is getting all the contact from the phonebook and display it. everything show except the checkbox.

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Oh, you are quite right! Sorry - brain hit a bad sector!


    Try this which works in IE:-

    Code:
    <html>
    <head>
    <script type = "text/javascript">
    
    function addNewRow(theTable){
    index = theTable.rows.length;
    nextRow =  theTable.insertRow(index);
    chkBox = nextRow.insertCell(0);
    txtBox1 = nextRow.insertCell(1);
    txtBox2 = nextRow.insertCell(2);
    index++;
    chkBox.innerHTML = "CheckBox "+index+ " <input type=checkbox name='cbox'+index>"; 
    indexN = (index*2)-1;
    txtBox1.innerHTML = "TextBox "+indexN+ " <input type= text name ='tbx"+indexN+"'>";
    indexN++;
    txtBox2.innerHTML = "TextBox "+indexN+ " <input type=text name='tbx"+indexN+"'>";
    }
    
    </script>
    </head>
    <body>
    <center>
    <form name= "myform">
    <table id= "myTable" cellpadding=5 cellspacing=5 border=1></table>
    </form>
    <br>
    <input type=button value="Insert New Row" onclick="addNewRow(myTable)"><br>
    </body>
    </html>
    Create the table, then populate it. e.g. document.myform.tbx2.value = "Whatever";
    Thank you for your help. The above codes works.

  • #9
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you everyone for your replies. My program is working now.

  • #10
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Oh, you are quite right! Sorry - brain hit a bad sector!


    Try this which works in IE:-

    Code:
    <html>
    <head>
    <script type = "text/javascript">
    
    function addNewRow(theTable){
    index = theTable.rows.length;
    nextRow =  theTable.insertRow(index);
    chkBox = nextRow.insertCell(0);
    txtBox1 = nextRow.insertCell(1);
    txtBox2 = nextRow.insertCell(2);
    index++;
    chkBox.innerHTML = "CheckBox "+index+ " <input type=checkbox name='cbox'+index>"; 
    indexN = (index*2)-1;
    txtBox1.innerHTML = "TextBox "+indexN+ " <input type= text name ='tbx"+indexN+"'>";
    indexN++;
    txtBox2.innerHTML = "TextBox "+indexN+ " <input type=text name='tbx"+indexN+"'>";
    }
    
    </script>
    </head>
    <body>
    <center>
    <form name= "myform">
    <table id= "myTable" cellpadding=5 cellspacing=5 border=1></table>
    </form>
    <br>
    <input type=button value="Insert New Row" onclick="addNewRow(myTable)"><br>
    </body>
    </html>
    Create the table, then populate it. e.g. document.myform.tbx2.value = "Whatever";
    Hi, i have change your code to the following but now i have a problem setting the checkbox value. i added document.contact.cbox.value = item.MobilePhoneGen.Value; but only the first checkbox has value . How do i add values into the other checkboxes too?

    Code:
    // filling table with received data
    		var table = document.getElementById('maintable');
    		var i; // iterator
    		var item; // pointer to item in received list
    		for (i = 0; (item = contacts.ReturnValue.getNext()) != undefined; ++i) {
    			index = table.rows.length;
    			nextRow = table.insertRow(index);
    			chkBox = nextRow.insertCell(0);
    			firstName = nextRow.insertCell(1);
    			lastName = nextRow.insertCell(2);
    			phone = nextRow.insertCell(3);
    			email = nextRow.insertCell(4)
    			index++;
    			chkBox.innerHTML = "<input type=checkbox name='cbox'+index>";
    			if (item.MobilePhoneGen != undefined) {
    				document.contact.cbox.value = item.MobilePhoneGen.Value;
    				alert(document.contact.cbox.value);
    
    			}
    			indexN = (index * 2) - 1;
    			if (item.FirstName != undefined) {
    				firstName.innerHTML = item.FirstName.Value;
    			}
    			indexN++;
    			if (item.LastName != undefined) {
    				lastName.innerHTML = item.LastName.Value;
    			}
    			indexN = (index * 3) - 1;
    			if (item.MobilePhoneGen != undefined) {
    				phone.innerHTML = item.MobilePhoneGen.Value;
    			}
    			indexN++;
    			if (item.EmailGen != undefined) {
    				email.innerHTML = item.EmailGen.Value;
    			}
    Last edited by wenn; 12-23-2010 at 08:55 AM.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    See Post #6.
    Create the table, then populate it. e.g. document.myform.tbx2.value = "Whatever";


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •