By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

innerHTML problem

P: 85
i have problem with innerHTML
i get the value of innerHTML of tr and modify the text
but when i try to put this text back in innerHTML it says unknown runtime error
im trying to append some paramaeter in the onclick url

[HTML]<table bgcolor= "#FFFFFF" width="150" border="0" cellpadding="0" cellspacing="0">
<tr id="xyz">
<td height="150" style="cursor:pointer; cursor: hand;" onClick="popup = window.open ('http://example.com/abc.html?xyz=aa&abc=ssdfd',_blank','height=450,wid th=500,scrollbars=yes,resizable=yes,toolbar=yes,me nubar=yes,status=1,location=yes'); return false">some code here
</td>
</tr>
</table>[/HTML]

Expand|Select|Wrap|Line Numbers
  1. window.onload=function(){
  2. var y=document.getElementById("xyz").innerHTML;
  3. var temp=y.substring(y.indexOf("window.open('")+13);
  4. y=y.substring(0,y.indexOf("window.open('")+13);
  5. y=y+temp.substring(0,temp.indexOf("'"))+"&xyzuser="+x+temp.substring(temp.indexOf("'"));
  6. document.getElementById("xyz").innerHTML=y;
  7. };
  8.  
Nov 5 '07 #1
Share this Question
Share on Google+
11 Replies


acoder
Expert Mod 15k+
P: 16,027
You've not defined "x" on line 5.
Nov 5 '07 #2

P: 85
x is in a code somewhere above before window.onload
Nov 5 '07 #3

acoder
Expert Mod 15k+
P: 16,027
temp.indexOf("'") on line 5 is finding the first single quote rather than the second one, so the extra parameter is added to the beginning which causes a syntax error.
Nov 5 '07 #4

P: 85
well temp start after 1st '
Expand|Select|Wrap|Line Numbers
  1. temp=y.substring(y.indexOf("window.open('")+13);
and i have used
Expand|Select|Wrap|Line Numbers
  1. alert(y);
which gave the the desired result
but when i put it in innerHTML, it gave unknown runtime error
Nov 5 '07 #5

acoder
Expert Mod 15k+
P: 16,027
and i have used
Expand|Select|Wrap|Line Numbers
  1. alert(y);
which gave the the desired result
but when i put it in innerHTML, it gave unknown runtime error
Did you put this alert after line 5?

In your onclick, there is a space between window.open and the opening brace ( while in your code checking for the index, there isn't.
Nov 5 '07 #6

P: 85
sorry for the silly mistake
yes the alert is after line 5 and i pasted a space after window.open here for better view whereas it is not in my original code
after alert i can see the changed value
Nov 5 '07 #7

acoder
Expert Mod 15k+
P: 16,027
Noticed a missing single quote:
Expand|Select|Wrap|Line Numbers
  1. _blank'
If you add the beginning quote, it should work.
Nov 5 '07 #8

P: 85
grrr i make a lot of mistakes when i paste my code
i removed some part from url when posting here and by mistake removed the ' before _blank as well. my code has the ' in it
Nov 5 '07 #9

P: 85
i made a sample code to check the error

[HTML]<HTML>
<HEAD>
</HEAD>
<BODY>
<table>
<tr id="xyz">
<td onclick="javascript:alert('hi');">hello</td></tr>
</table>
<script>
var x=document.getElementById("xyz").innerHTML;
var temp=x.substring(0,x.indexOf("alert('")+7);
x=x.substring(x.indexOf("alert('")+7);
x="hello"+x;
x=temp+x;
alert(x);
window.onload=function(){
document.getElementById("xyz").innerHTML=x;
};
</script>
</BODY>
</HTML>
[/HTML]
this code also gave the Unknown runtime error
Nov 5 '07 #10

acoder
Expert Mod 15k+
P: 16,027
Works in Firefox. Displays an alert "hellohi" as expected.
Nov 5 '07 #11

P: 85
hmmm well the code i was working on was for IE so i didnt test it in firefox and this code is not working in IE which i want it to
Nov 5 '07 #12

Post your reply

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