Webmaster Forum Rules | Posting Guide | Contact Us | Testimonials | Contributing Geek Program | Advertise on Geek/Talk
Welcome to the GeekTalk Webmaster Discussion Forums from GeekVillage.com

Click Here To Register. It's Free!

Go Back   geek/talk: Signature-free discourse for serious web publishers > YOUR CREATION: Building & Maintaining A Web Site > Web Development - Programming / Coding
User Name
Password
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 08-21-2005, 10:10 PM   #1
aredamkrik
Registered User
 
Join Date: Aug 2005
Posts: 15
Question events in JavaScript

I have a function that shows photos written in javascript. I want to be able to click a next, prev, or back button within that function. OnClick doesn't work aparently within the script heading. How do I trigger an event (mouse click) within a function?

<SCRIPT NAME="JAVASCRIPT">
<!--
function show_photo( pFileName, pTitle, pCaption)
{
var index=0;
while(pFileNames[index]!=pFileName){index++;**
if(pFileNames[index]==pFileName)
{
pFileName=pFileNames[index+1];
photoWin = window.open( "", "_self", "status,scrollbars,resizable,screenX=0,screenY=0,l eft=0,top=0");
photoWin.document.write('<html><head><title>' + pTitle + '</title><link rel="stylesheet" type="text/css" href="Pictures/Html/style_pics.css" /></head>');
photoWin.document.write('<BODY>');
photoWin.document.write(pCaption + '<p>');
photoWin.document.write('<img src="' + pFileName + '" height=65%><p>');
photoWin.document.write('</body></html>');
photoWin.document.close();

if (navigator.appName.substring(0,8) == "Netscape") photoWin.focus();

**
**
-->
</SCRIPT>
aredamkrik is offline   Reply With Quote
Old 08-22-2005, 04:21 AM   #2
georgec
Registered User
 
Join Date: Apr 2001
Posts: 519
Default

Hi:
Do you mean you wish to use JavaScript to simulate an actual click event, as if someone physically clicked on a button? If so, unfortunately as far as I know, that's not possible. JavaScript does support a click() method, but I've never gotten it to work as described. Now, if you mean you want function show_photo() to be executed onClick, that can be done many ways, the most common via the onClick event handler as an HTML attribute:

<button onClick="show_photo( pFileName, pTitle, pCaption)">Button</button>

Last edited by georgec; 08-22-2005 at 04:21 AM.
georgec is offline   Reply With Quote
Old 08-22-2005, 02:58 PM   #3
aredamkrik
Registered User
 
Join Date: Aug 2005
Posts: 15
Default passing a function or include files in Javascript?

hmm.. I was able to use this line

photoWin.document.write('<button OnClick="alert()">alert</button>');

Trying to put something within the alert is a different story.

photoWin.document.write('<button OnClick="alert('hey')">alert</button>');

I think the ' marks behave differently within a write statement.
Normally you can place one within the other, within the other, and so on (<button OnClick="alert('hey')">alert</button>).
I think within a write statement, each ' mark closes/opens the write statement.

but it does work like this

photoWin.document.write('<button OnClick=alert("hey")>alert</button>');

?????????????????????????

Anyways, I think I could use the function showphoto() in the same manner but there's still a problem. The function makes a new html doc in a new window meaning showphoto() is not defined within that html docand neither is the array pFileNames[]. Is there any way to pass the function/array to it or have an include file with it or something?

This is a simplified version that works to test with. It does show a photo if one exists named pic1.jpg.


<html>
<head>
<SCRIPT NAME="JAVASCRIPT">
<!--
var pFileNames = new Array(2);
pFileNames[0] ="pic1.jpg";
pFileNames[1] ="pic2.jpg";

function show_photo( pFileName)
{
var index=0;
while(pFileNames[index]!=pFileName){index++;**
if(pFileNames[index]==pFileName)
{

photoWin = window.open( "", "_self", "status,scrollbars,resizable,screenX=0,screenY=0,l eft=0,top=0");
photoWin.document.write('<html><head><title>' + pFileName + '</title></head>');
photoWin.document.write('<body>');
photoWin.document.write('I think Show Photo does not work because it\'s not defined in this window <p />');
photoWin.document.write('<img src="' + pFileName + '" height=65%><p>');
photoWin.document.write('<button OnClick=alert("works,_but_only_with_no_spaces?")>A lert</button>');
photoWin.document.write('<button OnClick=show_photo("pic1.jpg")>Show Photo</button>');
photoWin.document.write('</body></html>');
photoWin.document.close();

if (navigator.appName.substring(0,8) == "Netscape") photoWin.focus();

**
**
-->
</SCRIPT>
</head>
<body>
<button OnClick='alert("this is how alert should work")'>Alert</button> <p />
<button OnClick='show_photo("pic1.jpg")'>Show Photo</button>
</body>
</html>
aredamkrik is offline   Reply With Quote
Old 08-24-2005, 03:29 AM   #4
georgec
Registered User
 
Join Date: Apr 2001
Posts: 519
Default

Hi:
You mentioned:

photoWin.document.write('<button onClick="alert('hey')">alert</button>');

doesn't work for you. Try this instead:

document.write('<button onClick="alert(\'hey\')">alert</button>')
georgec is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript help needed coolshop Web Development - Programming / Coding 4 11-21-2001 02:01 PM
javascript popup error with AOL - PLEASE HELP theDirtiest Web Development - Programming / Coding 3 10-06-2001 08:19 AM
Javascript within Javascript ???? 1lit Web Design and Webmaster Issues 0 11-26-2000 04:19 PM
Javascript Website Waldo000000 Web Design and Webmaster Issues 3 04-22-2000 06:10 AM
Any good photo rotation javascript? notibrian Web Design and Webmaster Issues 1 11-13-1999 11:34 AM

Please support our advertisers. They ensure our survival.

All times are GMT -5. The time now is 10:29 PM.


GeekVillage.com is copyright © 1998-2015 Curiosity Cave - Science gifts for clever kids. All rights reserved.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.