Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerHTML not getting quotes ?

Status
Not open for further replies.

gorgered

Programmer
Dec 13, 2005
24
US
Hi,

I have iFrame in which I have a div and the contents of the div are dynamically changed using javascript. When I use innerHTML it clears quotes. So is there any way that I can get the contents of the tag?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
span.fill-in{background-color: yellow;}
</style>
</HEAD>

<BODY>
<FORM METHOD=POST ACTION="">
<INPUT TYPE="text" NAME="test_id" value="hello my test">
<INPUT TYPE="button" value="test" onClick="call('test_id')">
</FORM>
<div id="clause_text">
  this is a <span id="test_id1" class="fill-in">test</span> hello
</div>
<SCRIPT LANGUAGE="JavaScript">
<!--
  function call(obj){
   var id = document.getElementById(obj).name;
   var value = document.getElementById(id).value;
   //var spanObj = document.getElementById(id+"1");
   alert(document.getElementById('clause_text').innerHTML);
   //document.write($('clause_text').innerHTML);
  }

//-->
</SCRIPT>
</BODY>
</HTML>

Is there any why I could get the output with quotes for id and class?

Code:
this is a <span id="test_id1" class="fill-in">test</span>

Thanks
Gorge
 
If I'm not mistaken this might be a browser peculiarity. IE removes the quotes (if I'm not mistaken) when doing a view source. If you view source in FireFox, it shows the quotes.

Can you confirm that it only does this in IE? Also, could you post the text your are getting displayed now?

Take Care,
Mike
 
this has nothing to do with a view > source.

Not directly, but it very much has to do with how the browser treats the source, since the alert is in effect displaying partial source code.

Take Care,
Mike
 
could be, but when the OP comes back and says "there are no quotes", are you going to tell him it can't be done?

or are we then going to ask what he's trying to do, and go from there?

just trying to save some time.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I agree. The situation is kind of circumstancial, too.
Gorgered, could go into more detail on the purpose, like cLFlaVA said, and perhaps why it matters that the quotes are there.

You may also want to experiment somewhat with innerText vs. innerHTML as well.

Try the following code (I fixed a few JavaScript errors):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
span.fill-in{background-color: yellow;}
</style>
</HEAD>

<BODY>
<FORM METHOD=POST ACTION="">
<INPUT TYPE="text" NAME="test_id" value="hello my test">
<INPUT TYPE="button" value="test" onClick="call('test_id1')">
</FORM>
<div id="clause_text">
  this is a <span id="test_id1" class="fill-in">test</span> hello
</div>
<SCRIPT LANGUAGE="JavaScript">
<!--
function call(obj)
{
	var id = document.getElementById(obj).name;
	var value = document.getElementById(obj).value;
   //var spanObj = document.getElementById(id+"1");
   alert(document.getElementById('clause_text').innerHTML);
   //document.write($('clause_text').innerHTML);
}
//-->
</SCRIPT>
</BODY>
</HTML>

It displays with quotes in FireFox. However, IE omits the quotes. I don't believe this will pose an issue for functionality, since IE should know what the attributes and the corresponding values are.

Take Care,
Mike
 
Hi,

Thanks for quick responses, Well what I am trying to do?

I have some HTML content that comes from the DB which has span tag's and id of each span tag is PK of the table. Using the JavaScript I have to modify the innerHTML of the each span tag and with dynamic values that user enters into the text boxs and save the actual HTML content back into the DB with values. And I don't want to remove those quotes from each span tag as it might messup stored procedures which expect the id with in quotes.

Mike I haven't tried it in FF yet, is there any work around for IE?

Thanks
Gorge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top