473,414 Members | 1,605 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,414 software developers and data experts.

Calling Javascript function within innerHTML

34
Is there anyway to call a javascript function within an innerHTML call?

example:

Expand|Select|Wrap|Line Numbers
  1. var someelement =  document.createElement("input"); 
  2. var someelement2  =  document.createElement("input"); 
  3.  
  4. function test(str) { var str2 = test.substring(0,4); 
  5.                            return str2; }
  6.  
  7. someelement.ondblclick=function(){ 
  8.        document.getElementById('someelement2').innerHTML='<input id=\'blah\' value=\'test(this.value)\' >';
  9. }
  10.  
  11. \\I think this works if the quotes are escaped properly, but i haven't been \\successful in doing it.
  12.  
  13. someelement.ondblclick=function(){ 
  14.        document.getElementById('someelement2').innerHTML='<input id=\'blah\' value=\' '+test(+' this.value ' +) ' +\' >';
  15. }
  16.  
  17.  
any help will be much appreciated.
Dec 7 '07 #1
2 6619
Ferris
101 100+
Hi:

1st: input element can't use innerHTML.Only div element can use innerHTML.

2st: you create 2 input elements by using javascript,but you didn't add it into document.

I can't understand what you want to do,so tell me what you want,and I can post the code you want.
Dec 8 '07 #2
gsherp
34
Thanks for the reply.

I got around this problem by using an invisible input field in the innerHTML

Expand|Select|Wrap|Line Numbers
  1.  
  2. document.getElementById(something).innerHTML = data + '<input name=datafield id=datafield value=data class=nosee>';
  3.  
This seems to work for me, so i decided to just go with this method.
Dec 11 '07 #3

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

Similar topics

4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
1
by: Jamie | last post by:
I am using remote scripting to call a .NET page within a main page. The child page (child.aspx) returns html that contains dynamically created javascript methods (function test()). The parent...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.