473,732 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript function is not working in innerhtml.

7 New Member
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 "changeaddr ess" function in "addtable" function it doesn't work.

Thanks in advance.
Pooja
Mar 14 '07 #1
4 2914
mohsenhosseini
28 New Member
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 Recognized Expert Moderator MVP
In IE, you need the tbody tag after <table> for the table to display.
Mar 14 '07 #3
poojak
7 New Member
I am sending you the code in 2 parts.
Part 1:
[code]<html>
<head>
<script language="javas cript">
function addtable(){
document.getEle mentById('hidet his').style.dis play = 'none';
var ni = document.getEle mentById('myDiv ');
var numi = document.getEle mentById('theVa lue');
var num = (document.getEl ementById("theV alue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"D iv";
var newdiv = document.create Element('div');
newdiv.setAttri bute("id",divId Name);
newdiv.innerHTM L = "<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;Addr ess Type: </strong></td><td valign=middle>< table width=220 cellpadding=0 cellspacing=0 id=nopadding><t r><td><strong> Home:</strong> </td><td width=23><input name=address_ty pe id=home type=radio class=checkbox value=1 checked onClick='change address()' /></td><td><strong> &nbsp;&nbsp;&nb sp;Business:</strong> </td><td width=20><input name=address_ty pe id=business type=radio class=checkbox onClick='change address()' /></td><td><strong> &nbsp;&nbsp;&nb sp;Other:</strong> </td><td width=20><input name=address_ty pe id=other type=radio class=checkbox onClick='change address()' /></td></tr></table><tr id='h' style=display:i nline><td valign=middle>< strong><font color=ff0000>*</font>&nbsp;Addr ess Line1: </strong></td><td valign=middle>< input name=repeate_pa ssword2 type=text class=textinput id=repeate_pass word2 value=10238 /></td></tr><tr id='hh' style=display:i nline><td valign=middle>< strong>&nbsp;&n bsp; Address Line2: </strong></td><td valign=middle>< input name=repeate_pa ssword3 type=text class=textinput id=repeate_pass word3 /></td></tr><tr id='b' style=display:n one><td valign=middle>< strong>&nbsp;&n bsp;&nbsp;Busin ess Title: </strong></td><td valign=middle>< input name=repeate_pa ssword2 type=text class=textinput id=repeate_pass word2 value=10238/></td></tr><tr id='bb' style=display:n one><td valign=middle>< strong><font color=ff0000>*</font>&nbsp;Comp any Name: </strong></td><td valign=middle>< input name=repeate_pa ssword3 type=text class=textinput id=repeate_pass word3 /></td></tr><tr><td valign=middle>< strong><font color=ff0000>*</font>&nbsp;City :</strong></td><td valign=middle>< input name=repeate_pa ssword4 type=text class=textinput id=repeate_pass word4 value=Phoenix /></td></tr><tr><td valign=middle>< strong><font color=ff0000>*</font>&nbsp;Stat e/Province/Territory: </strong></td><td valign=middle>< select name=select3 class=selectsma ll><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_pa ssword5 type=text class=textinput id=repeate_pass word5 value=85258/></td></tr><tr><td valign=middle>< strong><font color=ff0000>*</font>&nbsp;Coun try: </strong></td><td valign=middle>< label><select name=select2 class=selectsma ll><option selected>USA</option></select></label></td></tr><tr><td valign=middle>< strong><font color=ff0000>*</font>&nbsp;Phon e Number: </strong></td><td valign=middle>< input name=repeate_pa ssword6 type=text class=textinput id=repeate_pass word6/></td></tr><tr><td valign=middle>< strong>&nbsp;&n bsp; Alternate Phone Number: </strong></td><td valign=middle>< input name=repeate_pa ssword7 type=text class=textinput id=repeate_pass word7/></td></tr><tr><td valign=middle>< strong>&nbsp;&n bsp; Fax Number:</strong></td><td valign=middle>< input name=repeate_pa ssword8 type=text class=textinput id=repeate_pass word8/></td></tr><tr><td colspan=2></td></tr></table>";
ni.appendChild( newdiv);
}

function changeaddress() {
if ((document.getE lementById('bus iness').checked )){
alert("pooja");
document.getEle mentById('h').s tyle.display = 'inline';
//document.getEle mentById(h).hei ght.value = '25px';
document.getEle mentById('hh'). style.display = 'inline';
//document.getEle mentById(hh).he ight.value = '25px';
document.getEle mentById('b').s tyle.display = 'inline';
document.getEle mentById('bb'). style.display = 'inline';
}
else {
document.getEle mentById('b').s tyle.display = 'none';
//document.getEle mentById(b).hei ght.value = '0px';
document.getEle mentById('bb'). style.display = 'none';
//document.getEle mentById(bb).he ight.value = '0px';
document.getEle mentById('h').s tyle.display = 'inline';
//document.getEle mentById(h).hei ght.value = '25px';
document.getEle mentById('hh'). style.display = 'inline';
//document.getEle mentById(h).hei ght.value = '25px';

}

}
</script></head>
Mar 19 '07 #4
poojak
7 New Member
<body>
<div id="mainbody">
<table border="0" cellspacing="0" cellpadding="0" align="center" id="content">
<tr>
<td class="row1"><t able 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><fon t color="ff0000"> *</font>&nbsp;Addr ess 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_t ype" type="radio" class="checkbox " id="home" onClick="change address();" value="1" checked> </td>
<td><strong>&nb sp;&nbsp;&nbsp; Business:</strong> </td>
<td width="20"><inp ut name="address_t ype" id="business" type="radio" class="checkbox " onClick="change address();" value="0"></td>
<td><strong>&nb sp;&nbsp;&nbsp; Other:</strong> </td>
<td width="20"><inp ut name="address_t ype" id="other" type="radio" class="checkbox " onClick="change address();" value="2"></td>
</tr></table>
<tr id="b" style="display: none"><td align="left" valign="middle" ><strong>&nbsp; &nbsp;&nbsp;Bus iness Title: </strong></td><td align="left" valign="middle" ><input name="business_ title" type="text" class="textinpu t" id="business_ti tle" value="10238" /></td></tr><tr id="bb" style="display: none"><td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;Comp any Name: </strong></td><td align="left" valign="middle" ><input name="company_n ame" type="text" class="textinpu t" id="company_nam e" /></td></tr><tr id="h" style="display: inline"><td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;Addr ess Line 1: </strong></td><td align="left" valign="middle" ><input name="address_1 " type="text" class="textinpu t" 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="textinpu t" id="address_2" /></td></tr>
<tr><td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;City : </strong></td>
<td align="left" valign="middle" ><input name="repeate_p assword4" type="text" class="textinpu t" id="repeate_pas sword4" value="Phoenix" /></td>
</tr>
<tr>
<td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;Stat e/Province/Territory: </strong></td>
<td align="left" valign="middle" ><select name="select3" class="selectsm all">
<option>AZ</option>
</select></td>
</tr>
<tr>
<td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;Zip/Postal Code: </strong></td>
<td align="left" valign="middle" ><input name="repeate_p assword5" type="text" class="textinpu t" id="repeate_pas sword5" value="85258" /></td>
</tr>
<tr>
<td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;Coun try: </strong></td>
<td align="left" valign="middle" ><label>
<select name="select2" class="selectmo nth">
<option selected>USA</option>
</select>
</label></td>
</tr>
<tr>
<td align="left" valign="middle" ><strong><fon t color="ff0000"> *</font>&nbsp;Phon e Number: </strong></td>
<td align="left" valign="middle" ><input name="repeate_p assword6" type="text" class="textinpu t" id="repeate_pas sword6" /></td>
</tr>
<tr>
<td align="left" valign="middle" ><strong>&nbsp; &nbsp; Fax Number:</strong></td>
<td align="left" valign="middle" ><input name="repeate_p assword8" type="text" class="textinpu t" id="repeate_pas sword8" /></td>
</tr>
<tr id="hidethis" style="display: inline;">
<td colspan="2" class="tbpaddin g" align="left" valign="middle" ><h6>Alternat e 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="javascrip t: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
4589
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 reverse of embedding JS in an html page with the script tag. (which is what I am doing in this case) Is this even possible?
7
1679
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 <span> tags on the client, hidden from the screen by @media classes. From a dynamically built menu of what was returned, the user selects wich report they want to view/print and a little jscript .innerHTML magic happens under the hood that copies...
7
3228
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 column need to be a date picker field. I know things will be easier with ASPX datagrid.
22
2352
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 to look like: <script language='JavaScript'> ...do something AJAX-y </script>
8
3216
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 javascript is not working. e.g. html content:
2
3156
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 then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
1
1548
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 txt1=document.awards.m_date_dateOfAchievement.value;
3
1714
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 get the content from another hidden div. I'm doing it this way to make it easier to add in more messages by simply putting more hidden divs on the page.
8
2142
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 cell. I've tried a bunch of different things but I'm not getting it. I'm a newbee to both html and javascript so be kind. Any example would be appreciated.
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.