473,387 Members | 1,673 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.

dynamically add content

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5.  
  6. <head>
  7.   <title></title>
  8.   <script >
  9.     function fun1()
  10.     {
  11.     document.body.innerHTML= "<input type=button value=clickme1 onclick='fun2()'>";
  12.     var code=document.head.script.innerHTML;
  13.     code+="function fun2() {document.write('hello'); } ";
  14.     document.head.body.script.innerHTML=code;
  15.     }
  16. </script >
  17. </head>
  18. <body  id="codes">
  19.     <input type=button value=clickme onclick="fun1()" />
  20.  
  21. </body>
  22.  
  23. </html>


i want to add a function directly in to the page ...how can it be done
this above progam is not working ...plz help
Oct 21 '09 #1
4 1977
Dormilich
8,658 Expert Mod 8TB
first of all, validate your HTML (http://validator.w3.org)

further, this code seems terribly outdated (so you might read a Javascript tutorial to get up to date)

and I don’t understand what the code should do… you try to copy code around when you’re probably better off just executing the function.

PS. please don’t hijack someone other’s thread if you have an unrelated question, just open a new thread.

and… welcome at bytes.com
Oct 21 '09 #2
acoder
16,027 Expert Mod 8TB
If you want to add JavaScript code to the head, try something like this:
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. var text = document.createTextNode("code here");
  3. script.appendChild(text);
  4. document.getElementsByTagName("head")[0].appendChild(script);
Oct 25 '09 #3
Dormilich
8,658 Expert Mod 8TB
@tomeshjain
the bold marked XHTML code will cause an error. the bold marked javascript code is just wrong.
you should also write your Javascript code in a CDATA section, otherwise an error will be thrown on every &, < and >.
Oct 25 '09 #4
acoder
16,027 Expert Mod 8TB
@Dormilich
True, or put it in a file and include it.
Oct 26 '09 #5

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

Similar topics

10
by: Free-Ed, Ltd. | last post by:
I am going nuts trying to find a paragraph in a book that described how to change the text content (HTML) in a DIV. Actually I have an array of HTML strings that I want to drop into the DIV,...
5
by: Tim Mulholland | last post by:
I am trying to create an ASPX page that, based on QueryString inputs, returns another file, in this case a WMA file. I do not want to do this by redirect, because these files are not available...
3
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? ...
2
by: Axel Dahmen | last post by:
HI, I want to dynamically add controls to a web page from within a common base class. Unfortunately, ASP.NET fails with "System.Web.HttpException: The Controls collection cannot be modified...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
6
by: TB | last post by:
Hi All: I have this page where a rows / cells are programmatically added to to table by pushing a button. The rows contain a textbox and a associated button. What I want to is to be able to...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.