Jump to content


Popup help


6 replies to this topic

#1 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 22 August 2006 - 06:22 AM

My script finds all files in a folder and link to them. What I want is a checkbox at my site. If the checkbox is checked, open any links clicked in a new window with the size 300x400.

If you need the script, I'll gladly post it :rolleyes:

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 22 August 2006 - 03:19 PM

Tad tricky, can JavaScript be used as a form action?
If so, you could add all the chackboxes as inputs (echoed with your PHP of course) that would look something like this.
<input type="checkbox" name="selected[]" value="<?php echo $filename; ?>" />

Then, in your processing form, you could make it send to a .js page with nothing but a loop that will use the window.open command with the filename and such. :biggrin:
Though, if that can't be done, then maybe using something like a button with the OnClick event handler, and have a function that will grab all the values of selected[] and pop them open.

#3 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 23 August 2006 - 02:39 PM

My problem is the window.open(), because the filename isnīt allways the same, it depends on what files that is in my folder. I need a script to fetch the filename, and then open that file in a new window.

Could it be done as simple as this:
<a href="#" onClick="window.open(set heigth and witdth etc here)">my random link gotten from folder</a>

#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 23 August 2006 - 03:59 PM

You completely missed what I just posted apparently...

I am aware of your dynamic images in the directory.
And you said originally you would like to open them all with one click via checkboxes and a submit button, correct?
I finally found my old window.open() syntax (I'm horrid at JavaScript, can't remember a dam thing).

Here's a small draft of an overall script, more or less.

<?php
if(!$_POST){ // If no post data (nothing has been submitted)
/* Your functions/code to retrieve all the files in a database, storing them into an array I hope */
?>
<form method="POST" action="<?php echo $PHP_SELF; ?>">
<?php
foreach($files as $file){ // Loop through and echo each file in the array
?>
<br /><input type="checkbox" name="selected[]" value="<?php echo $file; ?>" /> <strong><?php echo $file; ?></strong>
<?php
}
?>
<input type="submit" value="Open Images" />
</form>
<?php
}
else{ // Else if there IS post data
echo '<script language="Javascript" type="text/javascript">';
foreach($_POST['selected'] as $file){
echo 'window.open('.$file.', _blank, \'width=300,height=400\');';
}
echo '</script>';
}
}

Arg, I was going to do it mostly in JavaScript instead of using PHP to echo the JavaScript, but the are no real foreach loops in JavaScript, and the one I found that someone made was over my head...
Tad cruel in my opinion, but in theory would work.
Someone else who actually knows JavaScript could probably clean this up, since I can't find a good way to use something like a foreach loop in JavaScript. ;)

Edited by Demonslay, 23 August 2006 - 04:01 PM.


#5 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 23 August 2006 - 04:29 PM

lol,sorry to burst your bubble demonslay...

function targetChange()
{	
	var anchors = document.getElementsByTagName("a");
	
	if(document.getElementById('check').checked == 1) 
	{
		for(var i = 0; i < anchors.length; i++)
		{
			anchors[i].target = '_blank';
		}
	}
	else
	{	
		for(var i = 0; i < anchors.length; i++)
		{
			anchors[i].target = '_self';
		}
	}
	 	
}

<input type="checkbox" id="check" value="tumadreesuncochemuyviejo" onclick="targetChange()" />

<a href="http://google.com">test</a><br />
<a href="http://google.com">test2</a>

I am in no way a javascript 'expert' though so i would hope that works ;) (seems to with me), however it does not open the window in a certain size...why? because for some reason everytime i added that part the original window would show the action....i dunno, as i said im not great at JS.

Its something to work on i hope.


Matt.

===================


As you can see demonslay, i have used a simple loop against the length of the array (in this case the amount of hyper links in the page) as a foreach.

Edited by .Matt, 23 August 2006 - 04:34 PM.


#6 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 23 August 2006 - 05:18 PM

I never knew how to get the length of the anchor's array. The only JavaScript I am somewhat good at is a few event handlers and that's about it. :P

That's odd, I think his first post changed. I swear he said he wanted to open a ton of images in one click. ;)

Or is that another thread...

#7 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 24 August 2006 - 01:03 AM

Thatīs another thread.
Donīt know if I really got this right (Iīm a bit slow :unsure: ) but Iīll try it out. Thanks anyway ^_^





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users