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

embedded JS onclick problem

Status
Not open for further replies.

hyrogen

Programmer
Jul 10, 2003
60
GB
Hi there,

Ive got a problem where I have JS embedded in a page the Im dynamically included through ajax. Im executing the js in the embedded page by using the eval function.

My problem is I have an onclick event on an element in the embedded page, but when clicking on it, it says it cannot find the function. Here is the relevant code:

Calling Page:
<script>
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var page = xmlHttp.responseText;

document.getElementById("txtHint").innerHTML=page;

var start = page.indexOf('<script>');
var end = page.indexOf('<\/script>');
eval(page.substring(start+8,end));

}
}

</script>


</body>

<input type="input" value="click me" onClick="showHint()">

<div id="txtHint"></div>

Embedded Page:

<script>
function setMe() {
msg = document.getElementById("email").value;
alert(msg);
}
setMe();
</script>


<input type=text name=email id=email value="a@a.com" onClick="setMe();">
 
Sorted!

Had to use an anonymous function:

setMe = function() {
msg = document.getElementById("email").value;
alert(msg);
}

thanks anyway :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top