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

this.value is undefined, why?

Status
Not open for further replies.

zWaR

Programmer
Dec 1, 2004
20
SI
hello!
i'm actually new to JavaScript. There's something i don't understand. here's the piece of code first:
HTML:
Code:
<td class=\"tekst\" align=\"center\" value=$question_array[$pom] onClick=\"Enable(this.value)\">$question_array[$index_q]</td>

JavaScript:
Code:
<script type="text/javascript">
<!--
function Enable(table) {
var x=document.getElementById("preview_question");
var y=document.getElementById("edit_question");
x.disabled=false;
y.disabled=false;

var newInput=document.createElement("<input type='hidden' name='question' value=table />");
document.body.insertBefore(newInput);
}
//-->
</script>

The function Enable enables first two buttons - this works.
But why is the parameter table undefined? Does this.value work only on input tags? If so, what how can i execute similar action on table tag?

P.S.: the code posted is acutaly a part of PHP.
 
What if you did something like this?
Code:
<td class=\"tekst\" align=\"center\" onClick=\"Enable('$question_array[$pom]')\">$question_array[$index_q]</td>
Or you could put the value in a hidden form field.

Adam
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done." Andy Rooney.
 
I allready tried that, but it doesn't work.
 
this.value does not work because value is not a valid attribute of a table cell. Look here for valid table cell attributes.

Additionally, there is no line in the code you showed us that even references the variable you're passing in.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
this refers to a TD which cannot have a value (INPUTs have values). I'm not following all of your code - is this PHP?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
why is this code not working in IE6.0?
JS:
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
function Enable() {
		var preview=document.getElementById("preview_question");
		var edit=document.getElementById("edit_question");
		preview.disabled=false;
		edit.disabled=false;
	}
//-->
</script>

PHP:
Code:
echo "<option value=$pom onClick=\"Enable()\">$question_array[$index_k]";
echo "<input type=\"submit\" class=\"gumbi_short\" name=\"preview_question\" value=\"Preview\" id=\"preview_question\" disabled /> ";
echo "<input type=\"submit\" class=\"gumbi_short\" name=\"edit_question\" value=\"Edit\" id=\"edit_question\" disabled />";
 
An option tag can't exist outside of a SELECT tag.

This would be easier to debug if you could post the code after it has been parsed by PHP by selecting View / Source from the browser menu.

Adam
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done." Andy Rooney.
 
of course i have selection tag!! (i don't think it's necessery to poste the whole code)
and the code works in fire fox perceft!

the JavaScript code is even the same as in the MSDN help for JavaScript, so i really don't get it!
 
You can't post the relevant code that exists AFTER it is rendered in the browser, but you can post it BEFORE it's rendered? It's essentially the same thing, without all the hard-to-read backslashes.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
LOL
It's not a mather of that
Look, i'm programing a application, which is a littel bigger as you can imagine and the browser doesn't directly access my php file, so i can't post the browsers source.

If i execute this file isolated it won't work!

And i solved the question i stated:
1st onClick is not allowed to be used in option tag
2nd because onClick didn't work in the select tag, i used onChange event instead and now it works even on IE 6.0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top