Function Within A Function

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

so what's the difference if i post them in syntax or outside it. the threat will be same... isn't it? after all, syntax block is just same plain html after all :?

TESTING: Removed. Wrath of feyd was expected... :lol:
Last edited by n00b Saibot on Mon Apr 24, 2006 12:27 pm, edited 4 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You don't need to post your tests, so get back on topic.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

n00b Saibot wrote:so what's the difference if i post them in syntax or outside it. the threat will be same... isn't it? after all, syntax block is just same plain html after all :?

TESTING: Removed. Wrath of feyd was expected... :lol:
<QuickComment please="don't respond">

It's actually a problem with the mod that makes use of Geshi. The author of the mod claims it be unavoidable but there are apparently ways around it (ala

Code: Select all

).

</QuickComment>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

OK, so this piece of code here gives me an 'unknown runtime error'

Code: Select all

<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
		document.getElementById('picView').innerHTML = '<img src="../../uploads/'+who+'/'+pic+'" alt="Photo"><br><br><a href="javascript: void(0);" onClick="alert('+id+');">Get Link</a><p>Hurray! It works!</p>';
}
//-->
</script>
Whereas the same piece of code without the <p>Hurray! It works!</p> on it works.

Ideally I want the <p>Hurray! It works!</p> to be a hidden div with the link to the image inside of it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's hard to say what could be wrong at this point, so all I can recommend is using the DOM to build this content instead of using innerHTML.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

for the sake of testing, I also put that display:none nut that also fails to reproduce error on my test page.

Code: Select all

<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
 document.getElementById('picView').innerHTML = '<img src="../../uploads/'+who+'/'+pic+'" alt="Photo"><br><br><a href="javascript: void(0);" onClick="alert('+id+'); document.getElementById('+id+').style.display=\'\';">Get Link</a><p id='+id+' style="display:none">Hurray! It Runs!</p>';
}
//-->
</script>
<a href="javascript:showPicDetails('x', 'y', '1')">Click here</a><br />
<div id="picView"></div>
do you have more code than you're showing :?: maybe something in that part is messing it up... can you show me that code???
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

The page is about 300 lines of code, so there could be a lot of potential for something that's messing it up.

This is the function I have, and the way I am calling it.

Code: Select all

<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
	document.getElementById('picView').innerHTML = '<img src="../../uploads/'+who+'/'+pic+'" alt="Photo"><br><br><a href="javascript: void(0);" onClick="alert('+id+');">Get Link</a><p>Hurray! It works!</p>';
}
//-->
</script>

Code: Select all

<img src="thumbs/<?php echo $album_array['userid']; ?>/<?php echo $pica['img']; ?>" alt="Photo Album Picture" onClick="showPicDetails('<?php echo $pica['img']; ?>','<?php echo $album_array['userid']; ?>','<?php echo $pica['id']; ?>');" style="cursor: hand;">
Unless the error is in those lines of code somewhere, I'll have to go digging through the rest of it.

Edit: When that php code is evaluated, the result looks like this:

Code: Select all

<img src="thumbs/1/1145928974da8d48d3db.jpg" alt="Photo Album Picture" onClick="showPicDetails('1145928974da8d48d3db.jpg','1','74');" style="cursor: hand;">
Edit #2: Unfortunately, when I isolate my code... it works. =] So, bleh.. onto looking at the rest of the script.
Edit #3: Does it matter if this script is in the head of the document? Does it matter if I use the <!-- //--> comment lines?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

scottayy wrote:Does it matter if this script is in the head of the document? Does it matter if I use the <!-- //--> comment lines?
Rule #1: Put JS code in the <head> where possible except where rule #2 gets in the way
Rule #2: JS code in the head that calls any of the DOM methods/properties will likely fail if it executes inline with page loading... code stored in the head relating to DOM should only be executed once the page is fully loaded (since the "document" object isn't ready otherwise).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Any reason why you can't just call the nested function from within the main function and seperate the two?
Post Reply