473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Javascript function is not working in innerhtml.

7
I have write two different js function in a external file. one function write a table (I used innerHTML for this.) and another function is for showing/ hideing some rows depending on radio button selection. Both of these function works properly when used in HTML file, but when I use same showhide function in a table which is created by Javascript that function doesn't work at all. I am copying both JS functions here also, If someone can solve this problem.

Function to Add multiple tabel on a click a Link:
Expand|Select|Wrap|Line Numbers
  1. function addtable(){
  2. var ni = document.getElementById('myDiv');
  3. var numi = document.getElementById('theValue');
  4. var num = (document.getElementById("theValue").value -1)+ 2;
  5. numi.value = num;
  6. var divIdName = "my"+num+"Div";
  7. var newdiv = document.createElement('div');
  8. newdiv.setAttribute("id",divIdName);
  9. newdiv.innerHTML = "<table cellpadding=0 cellspacing=0><tr><td colspan=2 class=tbpadding align=left valign=middle><h6>Alternate Addresses</h6></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Address Type: </strong></td><td valign=middle><table width=220 cellpadding=0 cellspacing=0 id=nopadding><tr><td><strong> Home:</strong> </td><td width=23><input name=address_type id=home type=radio class=checkbox value=1 checked /></td><td><strong>&nbsp;&nbsp;&nbsp;Business:</strong> </td><td width=20><input name=address_type id=business type=radio class=checkbox /></td><td><strong>&nbsp;&nbsp;&nbsp;Other:</strong> </td><td width=20><input name=address_type id=other type=radio class=checkbox /></td></tr></table><tr id=h style=display:inline><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Address Line1: </strong></td><td valign=middle><input name=repeate_password2 type=text class=textinput id=repeate_password2 value=10238 /></td></tr><tr id=hh style=display:inline><td valign=middle><strong>&nbsp;&nbsp; Address Line2: </strong></td><td valign=middle><input name=repeate_password3 type=text class=textinput id=repeate_password3 /></td></tr><tr id=b style=display:none><td valign=middle><strong>&nbsp;&nbsp;&nbsp;Business Title: </strong></td><td valign=middle><input name=repeate_password2 type=text class=textinput id=repeate_password2 value=10238/></td></tr><tr id=bb style=display:none><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Company Name: </strong></td><td valign=middle><input name=repeate_password3 type=text class=textinput id=repeate_password3 /></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;City:</strong></td><td valign=middle><input name=repeate_password4 type=text class=textinput id=repeate_password4 value=Phoenix /></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;State/Province/Territory: </strong></td><td valign=middle><select name=select3 class=selectsmall><option>AZ</option></select></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Zip/Postal Code: </strong></td><td valign=middle><input name=repeate_password5 type=text class=textinput id=repeate_password5 value=85258/></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Country: </strong></td><td valign=middle><label><select name=select2 class=selectsmall><option selected>USA</option></select></label></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Phone Number: </strong></td><td valign=middle><input name=repeate_password6 type=text class=textinput id=repeate_password6/></td></tr><tr><td valign=middle><strong>&nbsp;&nbsp; Alternate Phone Number: </strong></td><td valign=middle><input name=repeate_password7 type=text class=textinput id=repeate_password7/></td></tr><tr><td valign=middle><strong>&nbsp;&nbsp; Fax Number:</strong></td><td valign=middle><input name=repeate_password8 type=text class=textinput id=repeate_password8/></td></tr><tr><td colspan=2><stromg><a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove<span> &gt;</span></a></strong></td></tr></table>";
  10. ni.appendChild(newdiv);
  11. }

Function for Showing or hiding table rows on selection of a radio button is:
Expand|Select|Wrap|Line Numbers
  1. function changeaddress(h,hh,b,bb) { 
  2.         if ((document.getElementById("business").checked)){
  3.             document.getElementById(h).style.display = 'inline';
  4.             document.getElementById(hh).style.display = 'inline';
  5.             document.getElementById(b).style.display = 'inline';
  6.             document.getElementById(bb).style.display = 'inline';
  7.         }
  8.         else {
  9.             document.getElementById(b).style.display = 'none';
  10.             document.getElementById(bb).style.display = 'none';
  11.             document.getElementById(h).style.display = 'inline';
  12.             document.getElementById(hh).style.display = 'inline';
  13.  
  14.         }
  15.  
  16. }
  17.  
When I call "changeaddress" function in "addtable" function it doesn't work.

Thanks in advance.
Pooja
Mar 14 '07 #1
4 2892
hi dear
please send your cpmplet page,which all of your functions in a page.
to i check and try to fix and work when you we put them in a external js file.

regards.
mh
Mar 14 '07 #2
acoder
16,027 Expert Mod 8TB
In IE, you need the tbody tag after <table> for the table to display.
Mar 14 '07 #3
poojak
7
I am sending you the code in 2 parts.
Part 1:
[code]<html>
<head>
<script language="javascript">
function addtable(){
document.getElementById('hidethis').style.display = 'none';
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<table cellpadding=0 cellspacing=0><tr><td colspan=2 class=tbpadding align=left valign=middle><h6>Alternate Addresses</h6></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Address Type: </strong></td><td valign=middle><table width=220 cellpadding=0 cellspacing=0 id=nopadding><tr><td><strong> Home:</strong> </td><td width=23><input name=address_type id=home type=radio class=checkbox value=1 checked onClick='changeaddress()' /></td><td><strong>&nbsp;&nbsp;&nbsp;Business:</strong> </td><td width=20><input name=address_type id=business type=radio class=checkbox onClick='changeaddress()' /></td><td><strong>&nbsp;&nbsp;&nbsp;Other:</strong> </td><td width=20><input name=address_type id=other type=radio class=checkbox onClick='changeaddress()' /></td></tr></table><tr id='h' style=display:inline><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Address Line1: </strong></td><td valign=middle><input name=repeate_password2 type=text class=textinput id=repeate_password2 value=10238 /></td></tr><tr id='hh' style=display:inline><td valign=middle><strong>&nbsp;&nbsp; Address Line2: </strong></td><td valign=middle><input name=repeate_password3 type=text class=textinput id=repeate_password3 /></td></tr><tr id='b' style=display:none><td valign=middle><strong>&nbsp;&nbsp;&nbsp;Business Title: </strong></td><td valign=middle><input name=repeate_password2 type=text class=textinput id=repeate_password2 value=10238/></td></tr><tr id='bb' style=display:none><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Company Name: </strong></td><td valign=middle><input name=repeate_password3 type=text class=textinput id=repeate_password3 /></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;City:</strong></td><td valign=middle><input name=repeate_password4 type=text class=textinput id=repeate_password4 value=Phoenix /></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;State/Province/Territory: </strong></td><td valign=middle><select name=select3 class=selectsmall><option>AZ</option></select></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Zip/Postal Code: </strong></td><td valign=middle><input name=repeate_password5 type=text class=textinput id=repeate_password5 value=85258/></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Country: </strong></td><td valign=middle><label><select name=select2 class=selectsmall><option selected>USA</option></select></label></td></tr><tr><td valign=middle><strong><font color=ff0000>*</font>&nbsp;Phone Number: </strong></td><td valign=middle><input name=repeate_password6 type=text class=textinput id=repeate_password6/></td></tr><tr><td valign=middle><strong>&nbsp;&nbsp; Alternate Phone Number: </strong></td><td valign=middle><input name=repeate_password7 type=text class=textinput id=repeate_password7/></td></tr><tr><td valign=middle><strong>&nbsp;&nbsp; Fax Number:</strong></td><td valign=middle><input name=repeate_password8 type=text class=textinput id=repeate_password8/></td></tr><tr><td colspan=2></td></tr></table>";
ni.appendChild(newdiv);
}

function changeaddress() {
if ((document.getElementById('business').checked)){
alert("pooja");
document.getElementById('h').style.display = 'inline';
//document.getElementById(h).height.value = '25px';
document.getElementById('hh').style.display = 'inline';
//document.getElementById(hh).height.value = '25px';
document.getElementById('b').style.display = 'inline';
document.getElementById('bb').style.display = 'inline';
}
else {
document.getElementById('b').style.display = 'none';
//document.getElementById(b).height.value = '0px';
document.getElementById('bb').style.display = 'none';
//document.getElementById(bb).height.value = '0px';
document.getElementById('h').style.display = 'inline';
//document.getElementById(h).height.value = '25px';
document.getElementById('hh').style.display = 'inline';
//document.getElementById(h).height.value = '25px';

}

}
</script></head>
Mar 19 '07 #4
poojak
7
<body>
<div id="mainbody">
<table border="0" cellspacing="0" cellpadding="0" align="center" id="content">
<tr>
<td class="row1"><table width="100%" cellspacing="0" id="profile">
<tr>
<td colspan="3">
<form name="form1" method="post" action="">
<table cellpadding="0" cellspacing="0" id="createlogin">
<tr>
<td colspan="2" align="left" valign="middle">
<h6>Default Adddress </h6>
<div align="left"></div></td>
</tr>
<tr>
<td width="183" align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;Address Type: </strong></td>
<td width="540" align="left" valign="middle">
<table width="220" cellpadding="0" cellspacing="0" id="nopadding">
<tr>
<td><strong> Home:</strong> </td>
<td width="23"> <input name="address_type" type="radio" class="checkbox" id="home" onClick="changeaddress();" value="1" checked> </td>
<td><strong>&nbsp;&nbsp;&nbsp;Business:</strong> </td>
<td width="20"><input name="address_type" id="business" type="radio" class="checkbox" onClick="changeaddress();" value="0"></td>
<td><strong>&nbsp;&nbsp;&nbsp;Other:</strong> </td>
<td width="20"><input name="address_type" id="other" type="radio" class="checkbox" onClick="changeaddress();" value="2"></td>
</tr></table>
<tr id="b" style="display:none"><td align="left" valign="middle"><strong>&nbsp;&nbsp;&nbsp;Business Title: </strong></td><td align="left" valign="middle"><input name="business_title" type="text" class="textinput" id="business_title" value="10238" /></td></tr><tr id="bb" style="display:none"><td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;Company Name: </strong></td><td align="left" valign="middle"><input name="company_name" type="text" class="textinput" id="company_name" /></td></tr><tr id="h" style="display:inline"><td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;Address Line 1: </strong></td><td align="left" valign="middle"><input name="address_1" type="text" class="textinput" id="address_1" value="10238" /></td></tr><tr id="hh" style="display:inline"><td align="left" valign="middle"><strong>&nbsp;&nbsp; Address Line 2: </strong></td><td align="left" valign="middle"><input name="address_2" type="text" class="textinput" id="address_2" /></td></tr>
<tr><td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;City: </strong></td>
<td align="left" valign="middle"><input name="repeate_password4" type="text" class="textinput" id="repeate_password4" value="Phoenix" /></td>
</tr>
<tr>
<td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;State/Province/Territory: </strong></td>
<td align="left" valign="middle"><select name="select3" class="selectsmall">
<option>AZ</option>
</select></td>
</tr>
<tr>
<td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;Zip/Postal Code: </strong></td>
<td align="left" valign="middle"><input name="repeate_password5" type="text" class="textinput" id="repeate_password5" value="85258" /></td>
</tr>
<tr>
<td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;Country: </strong></td>
<td align="left" valign="middle"><label>
<select name="select2" class="selectmonth">
<option selected>USA</option>
</select>
</label></td>
</tr>
<tr>
<td align="left" valign="middle"><strong><font color="ff0000">*</font>&nbsp;Phone Number: </strong></td>
<td align="left" valign="middle"><input name="repeate_password6" type="text" class="textinput" id="repeate_password6" /></td>
</tr>
<tr>
<td align="left" valign="middle"><strong>&nbsp;&nbsp; Fax Number:</strong></td>
<td align="left" valign="middle"><input name="repeate_password8" type="text" class="textinput" id="repeate_password8" /></td>
</tr>
<tr id="hidethis" style="display:inline;">
<td colspan="2" class="tbpadding" align="left" valign="middle"><h6>Alternate Addresses </h6></td>
</tr>
<tr>
<td colspan="2" align="left" valign="middle">
<table id="addanother" cellpadding="0" cellspacing="0"><tr><td id="adhere"></td></tr></table> </td>
</tr> <tr>
<td colspan="2" align="left" valign="middle">
<input type="hidden" value="0" id="theValue" /> <div id="myDiv"> </div> </td>
</tr>
<tr>
<td colspan="2" align="left" valign="middle"><a href="javascript:addtable();"><strong>Add an Additional Address<span> &gt;</span></strong></a><strong></strong></td>
</tr>
</table> </form></td></tr></table></td></tr> </table></td></tr></table></div></body></html>[/code]
---------------------------------------------
In default address section whicn you click on business radio button it will display to addtional rows but the same function doesn't work when I click on business radio button in Add Additional Address.
Thanks for your time.
Pooja
Mar 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
7
by: e | last post by:
I've been having an extremely difficult time finding an answer to this in IE / js groups, so I thought I'd try here. I've got an aspx page that delivers loads of report data into custom-named...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
22
by: Christopher Nelson | last post by:
I have a little menu system which essentially takes HTML like: <div id='foo'></div> and retrieves foo.shtml from the server and inserts it inside the <div>. But sometimes I'd like foo.shtml...
8
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
1
by: bekkem | last post by:
how to give a hyperlink to view in the following code <script language="javascript" type="text/javascript"> function addtoGrid(){ alert("working"); var...
3
by: Steve | last post by:
Hi; I'm working on a demo of using a timer on a web site that is made visible by making a div visible. My "PopIn Box" div is empty on the page. Before making it visible I used javascript to...
8
by: James Kimble | last post by:
Yeah I'm sure this is a stupid question. I've got a javascript source file with functions (creates a bar graph) I want to call from inside an html table cell so that the graph appears in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.