Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
how to access innerhtml element
Old 01-02-2007, 10:54 PM how to access innerhtml element
luz
Junior Talker

Posts: 2
Trades: 0
Hi guys...i'm kinda new in this js language...i was wondering can anybody help me with this code....well problem maybe sound a bit silly..well I was wondering how to get the all the value from the txtbox so that,I can validate all the data that have been key in by the user....thanking u all in advance for your time in reviewing my msg...may god bless u all.
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var numLinesAdded = 0;
function generateRow() {
var d=document.getElementById("div");
var addbut=document.getElementById("addsub");
d.innerHTML+="<table width='90%' bgcolor='#E9E9E9' border='0' cellpadding='0' cellspacing='0'><tr class='ContentTableText'><td>Name</td><td><input name='ConNameMs[]' type='text' id='ConNameMs[]' class='ContentTableText' size='38' /></td></tr><tr class='ContentTableText'><td>Address</td><td><input name='ConAdd[]' type='text' id='ConAdd[]' class='ContentTableText' size='38' /></td></tr><tr class='ContentTableText'><td>Age</td><td><input name='ConAge[]' type='text' id='ConAge[]' class='ContentTableText' size='38' /></td></tr></table><br>";
//d.innerHTML+="<input type='text' maxlength='5' name='txt1_" + numLinesAdded + "' onkeypress='focusNext(this)'>";
numLinesAdded++;
if(numLinesAdded=="5"){
addbut.disabled = true;
}
}
function test(){
alert("hi");
var thediv=document.getElementById("div");
var theelementcon=thediv.getElementsByTagName("input");
for(i=0;i<theelementcon.length;i++){
theelementcon[i].innerHTML=document.getElementById("ConNameMs[]").value;
}
}
</script>
</head>
<body>
<div id="div" align="center"></div>
<input type="button" value="Add Contact" id="addsub" onclick="generateRow()" class="ContentTableText"/>
<input type="button" value="Test" id="test" onclick="test()" class="ContentTableText"/>
</body>
</html>
luz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-03-2007, 03:23 AM Re: how to access innerhtml element
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Well since you're new to the language, what programming knowledge/experience do you have?

InnerHTML is a Microsoft proprietary extension, however, benchmarking showed it was fast for browsers that did support this, so I used this method, for the other browsers, I created patterns to extract the HTML content and had to create the elements using the DOM API. This was working on AJAX applications, which the content grabbed from the server was HTML formatted.

What you'll need to learn is how to do innerHTML using DOM API, how to strip the content using pattern matching (regular expressions).

http://mastercomputers.uni.cc/ObJAX/objax_example.js

The getMessages() function is the area that goes through DOM creation. Unfortunately I can't show you yet how to do it with your above source, so hopefully you can read through this script and understand that function (been invited out with a few friends, so just trying to be quick in answering). Basically the splits are where I wanted to seperate the text from the tags, so I could redo them. User grabs the username out of the string I'll show below, Time grabs the GMT formatted time below and Message grab what the user entered.

The content I'm working with it is:

HTML Code:
<p class="OJ_Output"><span class="OJ_UserName">Username</span>: (<span class="OJ_TimeStamp">Wed, 03 Jan 2007 20:15:55 GMT</span>) - <span class="OJ_Message">Here's the message.</span></p>
That will be inserted, either by innerHTML or appendChild(fragment), where fragment is the part of the document I had to recreate using DOM, innerHTML being easier to use. You just probably want to learn how the stripping happens and understand my patterns to understand what you need to do. If you have all the information in a string, then understanding the string and what you need to grab out of it would help, if the information varies a lot, then you may need multiple patterns to match it.

Cheers,

MC

And I apologise for leaving without answering.
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Reply     « Reply to how to access innerhtml element
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10184 seconds with 12 queries