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 escaping correct?

Status
Not open for further replies.

smitheroo

Programmer
Aug 30, 2008
15
0
0
GB
Hello,

Does anyone know why this isn't working? (on the last line of the script - 'out.innerHTML').

I presumed that I could add 'table' 'tr' and 'td' tags because it was working when I just had a radio button in the script.

I'm going to try combining innerhtml tags at some stage as I have a feeling the way I've written it might be overkill.

thanks
ian

Code:
<script type="text/javascript">
function copy() {
var sel = document.getElementById("problem2");
var text = sel.options[sel.selectedIndex].value;
var sel2 = document.getElementById("product2");
var text2 = sel2.options[sel2.selectedIndex].value;
var sel3 = document.getElementById("process2");
var text3 = sel3.options[sel3.selectedIndex].value;
var out = document.getElementById("output");
out.innerHTML += "<table>" + "<tr>" + "<td>" + "<input type=\"radio\" name=\"ouputradio\">" "<\/td>" + "<td>" + text + "<\/td>" + "<td>" + text2  + "<\/td>" + "<td>" + text3 + "<\/td>" + "<td>" + "<\/td>" + "<\/tr>"+ "<\/table>";
}
 </script>
 
Hi

No need to escape forward slash ( / ). No need to concatenate the string by tags. Not a brilliant idea to create a separate [tt]table[/tt] for each row.
Code:
out.innerHTML += "<table><tr><td><input type=\"radio\" name=\"ouputradio\"></td><td>" + text + "</td><td>" + text2  + "</td><td>" + text3 + "</td><td></td></tr></table>";

Feherke.
 
That's got it. Well done. thanks.

I'm just doing a standalone training html, so it's not going to be examined by anyone technical.

cheers
Ian
 
Hi,

Me again. just got a quick question.

How do I amend this script so that it works with text boxes ('amount' and 'comment'), it's origianlly written for three drop downs.

I've tried changed selectedindex to 'text' but i think i'm overlooking something else to change.

best regards

Ian

Code:
<script type="text/javascript">
function copy() {
var sel = document.getElementById("actiondrop");
var text = sel.options[sel.selectedIndex].value;
var sel2 = document.getElementById("amount");
var text2 = sel2.options[sel2.selectedIndex].value;
var sel3 = document.getElementById("comment");
var text3 = sel3.options[sel3.selectedIndex].value;
var out = document.getElementById("output");
out.innerHTML += "<table border=\"0\"><tr><td align=\"left\" width=\"30%\">" + text2 + "</td><td align=\"left\" width=\"20%\">" + text  + "</td><td align=\"left\" width=\"40%\">" + text3 + "</td><td></td></tr></table>";
}
 </script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top