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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in getting innertext

Status
Not open for further replies.

plarsen

Programmer
Jul 30, 2002
27
DK
Hi

What's wrong with this code?

-- code start --
1 function pdf() {
2 flt = "source"+document.form1.elements["ReferencesSTD"].value;
3 if (document.all.flt1.innerText == "") {
4 document.all.pdf.innerText = "";
5 }
6 else {
7 document.all.pdf.innerText = &quot;<a href='&quot;+flt+&quot;' target='_new'><img src='images/pdf.gif' title='Click to see the standard in PDF!'></a>&quot;;
8 }
9 }
-- code end --

The variable flt eg. contains &quot;source3&quot;, but everytime i run the code it says error in line 3. &quot;Is null or not an object!&quot;

Can someone tell me what's wrong?

/Peter Larsen
 
for starters, this
flt = &quot;source&quot;+document.form1.elements&quot;ReferencesSTD&quot;.value;

should be
flt = &quot;source&quot;+document.form1.elements[&quot;ReferencesSTD&quot;].value;

it might have just been the tgml though

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Hi

I'll try again, there was some errors in the first code.

-- Code start --
1 function pdf() {
2 flt = &quot;source&quot;+document.form1.elements[&quot;ReferencesSTD&quot;].value;
3 if (document.all.flt.innerText == &quot;&quot;) {
4 document.all.pdf.innerText = &quot;&quot;;
5 }
6 else {
7 document.all.pdf.innerText = &quot;<a href='&quot;+flt+&quot;' target='_new'><img src='images/pdf.gif' title='Click to see the standard in PDF!'></a>&quot;;
8 }
9 }
-- Code end --

And now the form.

-- Code start --
10 <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
11 <select name=&quot;ReferencesSTD&quot; size=&quot;1&quot; id=&quot;ReferencesSTD&quot; class=&quot;dropdown&quot; onchange=&quot;pdf()&quot;>
12 <option value=0>- Please select -</option>
13 <option value=&quot;3&quot;>ISO9001</option>
14 <option value=&quot;4&quot;>ISO14001</option>
15 <option value=&quot;5&quot;>OHAS18001</option>
16 </select>
17 <span name=&quot;pdf&quot;></span> 
18 <input name=&quot;StandardComment&quot; type=&quot;text&quot; value=&quot;&quot; size=&quot;15&quot; maxlength=&quot;15&quot;></font>
19 <font color=&quot;#FFFFFF&quot;><span name=&quot;source3&quot;>upload\files\iso9001.pdf</span></font>
20 <font color=&quot;#FFFFFF&quot;><span name=&quot;source4&quot;></span></font>
21 <font color=&quot;#FFFFFF&quot;><span name=&quot;source5&quot;></span></font>
22 </form>
-- Code end --

ftl should be used to find some text in the span areas in the form. Eg. if flt = &quot;source3&quot; in line 2 it should take the text from source3.innerText (<span name=&quot;source3&quot;></span>) line 19 and put it into the pdf.innerText (<span name=&quot;pdf&quot;></span>) in line 17 contains the line &quot;upload\files\iso9001.pdf&quot;.

But the error occure in line 3.

I hope that you can see what i want to do, and can give me some help on how to do it right.

/Peter Larsen
 
Peter,

This will fix most of the errors you are getting:

Code:
<html>
<head>
<script type=&quot;text/javascript&quot;>
function pdf()
{
	var formObj = document.forms[&quot;form1&quot;];
	var flt = &quot;source&quot; + formObj.ReferencesSTD[formObj.ReferencesSTD.selectedIndex].value;
	if (document.getElementById(flt).innerText == &quot;&quot;) {
		document.getElementById('pdf').innerText = &quot;&quot;;
	} else {
		document.getElementById('pdf').innerText = &quot;<a href='&quot;+flt+&quot;' target='_new'><img src='images/pdf.gif' title='Click to see the standard in PDF!'></a>&quot;;
	}
}
</script>
</head>

<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
	<select name=&quot;ReferencesSTD&quot; size=&quot;1&quot; id=&quot;ReferencesSTD&quot; class=&quot;dropdown&quot; onchange=&quot;pdf()&quot;>
		<option value=0>- Please select -</option>
		<option value=&quot;3&quot;>ISO9001</option>
		<option value=&quot;4&quot;>ISO14001</option>
		<option value=&quot;5&quot;>OHAS18001</option>
	</select>
	<span id=&quot;pdf&quot;></span>
	<input name=&quot;StandardComment&quot; type=&quot;text&quot; value=&quot;&quot; size=&quot;15&quot; maxlength=&quot;15&quot;></font>
	<font color=&quot;#FFFFFF&quot;><span id=&quot;source3&quot;>upload\files\iso9001.pdf</span></font>
	<font color=&quot;#FFFFFF&quot;><span id=&quot;source4&quot;></span></font>
	<font color=&quot;#FFFFFF&quot;><span id=&quot;source5&quot;></span></font>
</form>
</body>
</html>

I'm still not 100% sure if the functionality is as you desire, but now the errors are gone, you should be able to rework it a bit more.

Hope this helps,

Dan
 
Hi Dan

Nothing changed!

I am still getting an error:

Error: Object doesn't support this property or method

The error occures in the line with:

if (document.getElementById(flt).innertext == &quot;&quot;) {

I hope you or anyone else can help me!

/Peter
 
Peter,

That was weird - my post seemed to have some characters stripped out of it.

Try this:

Code:
<html>
<head>
<script type=&quot;text/javascript&quot;>
function pdf()
{
    var formObj = document.forms [ &quot;form1 &quot; ];
	if (formObj.ReferencesSTD[formObj.ReferencesSTD.selectedIndex].value == 0) return;
	var flt = &quot;source&quot; + formObj.ReferencesSTD[formObj.ReferencesSTD.selectedIndex].value;

    if (document.getElementById(flt).innerText == &quot;&quot;) {
        document.getElementById('pdf').innerText = &quot;&quot;;
    } else {
        document.getElementById('pdf').innerText = &quot;<a href='&quot;+flt+&quot;' target='_new'><img src='images/pdf.gif' title='Click to see the standard in PDF!'></a>&quot;;
    }
}
</script>
</head>

<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
    <select name=&quot;ReferencesSTD&quot; size=&quot;1&quot; id=&quot;ReferencesSTD&quot; class=&quot;dropdown&quot; onchange=&quot;pdf()&quot;>
        <option value=0>- Please select -</option>
        <option value=&quot;3&quot;>ISO9001</option>
        <option value=&quot;4&quot;>ISO14001</option>
        <option value=&quot;5&quot;>OHAS18001</option>
    </select>
    <span id=&quot;pdf&quot;></span>
    <input name=&quot;StandardComment&quot; type=&quot;text&quot; value=&quot;&quot; size=&quot;15&quot; maxlength=&quot;15&quot;></font>
    <font color=&quot;#FFFFFF&quot;><span id=&quot;source3&quot;>upload\files\iso9001.pdf</span></font>
    <font color=&quot;#FFFFFF&quot;><span id=&quot;source4&quot;></span></font>
    <font color=&quot;#FFFFFF&quot;><span id=&quot;source5&quot;></span></font>
</form>
</body>
</html>

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top