JavaScript and client side scripting.
Moderator: General Moderators
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Mon Apr 24, 2006 10:54 am
I have a function that is called and writes some HTML to the page. Inside this HTML should be another javascript function triggered by onClick.
Code: Select all
<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
document.getElementById('picView').innerHTML = '<img src="../../uploads/'+who+'/'+pic+'" alt="Photo"><p id="'+id+'"><a href="javascript: void(0);" onClick="showLink(pic,who,id);">Get Link</a></p><div id="'+id+'" style="display:none;">stuff</td>';
}
function showLink(pic,who,id){
document.getElementById(''+id+'').style.display = 'block';
}
//-->
</script>
I'm having all kinds of trouble with this one.
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.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon Apr 24, 2006 11:00 am
any specific reason you wanna do this?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Mon Apr 24, 2006 11:05 am
Yes. I have a photo gallery. When a thumb is clicked I want to display the full version. Then I want underneath that a link that when clicked, shows the URL to the full version.
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.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon Apr 24, 2006 11:18 am
forgive me, I didn't read it carefully. Can you tell me what problem/error message exactly do you get?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Mon Apr 24, 2006 11:24 am
I have altered the code a bit.
Code: Select all
<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
document.getElementById('picView').innerHTML = '
<img src="../../uploads/'+who+'/'+pic+'" alt="Photo">
<p id="'+id+'"><a href="javascript: void(0);" onClick="showLink(id);">Get Link</a></p>';
}
function showLink(id){
document.getElementById(id).style.display = 'block';
}
//-->
</script>
This gives me the error "Undetermined String Constant"
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 24, 2006 11:25 am
using the syntax system, it becomes a bit more clear: the even will not know what pic, who and id are.
Code: Select all
<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
document.getElementById('picView').innerHTML = '<img src="../../uploads/'+who+'/'+pic+'" alt="Photo"><p id="'+id+'"><a href="javascript: void(0);" onclick="showLink(\'' + pic + '\',\'' + who + '\',\'' + id + '\');">Get Link</a></p><div id="'+id+'" style="display:none;">stuff</td>';
}
function showLink(pic,who,id){
document.getElementById(id).style.display = 'block';
}
//-->
</script>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 24, 2006 11:26 am
scottayy wrote: I have altered the code a bit.
This gives me the error "Undetermined String Constant"
Javascript doesn't (generally) support multiple line strings.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon Apr 24, 2006 11:30 am
feyd has cleared up the cause for your error, but the additional pic and who params are not reqd.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Mon Apr 24, 2006 11:32 am
OK, let me try this on one line, with the syntax highlighter.
Code: Select all
<script type="text/javascript">
<!--
function showPicDetails(pic,who,id){
document.getElementById('picView').innerHTML = '<img src="../../uploads/'+who+'/'+pic+'" alt="Photo"><p><a href="javascript: void(0);" onClick="showLink(id);">Get Link</a></p><div id="'+id+'" style="display: none;">stuff</div>';
}
function showLink(id){
document.getElementById(id).style.display = 'block';
}
//-->
</script>
Edit: unknown runtime error
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.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon Apr 24, 2006 11:39 am
you again made the same mistake.
onClick="showLink(id);" should be onClick="showLink('+id+');"
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Mon Apr 24, 2006 11:51 am
OK, sorry guys, I'm just not understanding this.
The following works:
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>';
}
//-->
</script>
However, when I add any HTML unto the end of the function, I get an 'Unknown Runtime Error'.
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 24, 2006 11:53 am
Any html?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Mon Apr 24, 2006 11:54 am
It appears so.
Consider the above code that does work (in IE at least)
If I add <p>Stuff</p> onto the end of it, I get the runtime error.
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.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon Apr 24, 2006 12:07 pm
I don't have any problem doing whatever you mentioned... My test script being
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 Runs!</p>';
}
//-->
</script>
<a href="javascript:showPicDetails('x', 'y', '1')">Click here</a><br />
<div id="picView"></div>
edit: i dunno why forum is converting : to : pickle, note this one
edit 2: strange it converted & #058; back to : outside the syntax block. the second : above is a entity representation...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 24, 2006 12:15 pm
n00b Saibot wrote: edit: i dunno why forum is converting : to :
pickle, note this one
That's not pickles problem, nor a problem with the board. It is the protection systems of the board doing that.
n00b Saibot wrote: edit 2: strange it converted & #058; back to : outside the syntax block. the second : above is a entity representation...
The board recognises entities and makes them inline.