Jump to content

Recommended Posts

<?php
if($path = 1){
$file=$_GET['file'];
$path = "../htdocs/$file";
}else {
$path = "../htdocs/";
}
$i = 0;
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
$i = $i + 1;
?>
<script language="text/javascript">
function editPopup(){
window.open('/editor.php?filename=$file', "myWindow", "status=1, height=550, width=850, resizable=0");
</script>
<?php
echo "<form method='get' action='/editor.php?filename=$file'>$i: <input type=text name='filename' value='$file'> <input type='submit' value='EDIT' onClick='editPopup()'></form><br>";

}
closedir($dh);
?>

I need this to work. What it is supposed to do is let the user click on a button, the EDIT on, and then have a pop up window show up... but this is not working...! Dont worry about the top stuff, just basically the javascript, and the form. I need help to get those two to work together.


thanks
Link to comment
https://forums.phpfreaks.com/topic/12244-php-with-a-bit-of-javascript/
Share on other sites

no i don't really know what you mean but here's a couple things you need to fix. they may or may not fix your problem i don't know cuz i don't know what you mean. even though these things i pointed out are php related, it sounds to me like you need to be asking this in the javascript section anyways.
[!--quoteo(post=384993:date=Jun 17 2006, 10:22 AM:name=JP128)--][div class=\'quotetop\']QUOTE(JP128 @ Jun 17 2006, 10:22 AM) [snapback]384993[/snapback][/div][div class=\'quotemain\'][!--quotec--]
<?php
if($path [!--coloro:red--][span style=\"color:red\"][!--/coloro--]==[!--colorc--][/span][!--/colorc--] 1){
$file=$_GET['file'];
$path = "../htdocs/$file";
}else {
$path = "../htdocs/";
}
$i = 0;
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
$i = $i + 1;
?>
<script language="text/javascript">
function editPopup(){
window.open('/editor.php?filename=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]<?= $file ?>[!--colorc--][/span][!--/colorc--]', "myWindow", "status=1, height=550, width=850, resizable=0");
</script>
<?php
echo "<form method='get' action='/editor.php?filename=$file'>$i: <input type=text name='filename' value='$file'> <input type='submit' value='EDIT' onClick='editPopup()'></form><br>";

}
closedir($dh);
?>

I need this to work. What it is supposed to do is let the user click on a button, the EDIT on, and then have a pop up window show up... but this is not working...! Dont worry about the top stuff, just basically the javascript, and the form. I need help to get those two to work together.
thanks
[/quote]
You can't just change the submit button to do that.

If you want the form to be submit to a new window, specify a different target for the form element.

800th post! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
[!--quoteo(post=385114:date=Jun 17 2006, 05:11 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 17 2006, 05:11 PM) [snapback]385114[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can't just change the submit button to do that.

If you want the form to be submit to a new window, specify a different target for the form element.

800th post! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
[/quote]

You just reminded me...
If you don't need any data apart from the filename to appear in the popup then you don't need the action on the form and can just change the button's type from submit to button. However, to find the real problem, I would still recommend Firefox's Javascript Console.
[!--quoteo(post=385158:date=Jun 17 2006, 06:51 PM:name=JP128)--][div class=\'quotetop\']QUOTE(JP128 @ Jun 17 2006, 06:51 PM) [snapback]385158[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hmm, it isnt working still.
[/quote]

Have you tried looking at it in the Javascript console yet?
Yea, I am looking at the console, it said undefined, but I re-did the entire script and it works now, but
now it keeps going to one file... the last file in the directory
here is the code.


<?php
if($path == 1){
$file=$_GET['file'];
$path = "../htdocs/$file";
}else {
$path = "../htdocs/";
}
$i = 0;
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
$i = $i + 1;
?>
<script language="JavaScript1.2">
function openwindow()
{
window.open("/editor.php?filename=<?php echo $file; ?>", "mywindow", "menubar=0,resizable=0,width=850,height=550,location=1");
}
</SCRIPT>
<?php
echo "<input type=text name='filename' value='$file'> <input type='submit' value='EDIT' onClick='openwindow()'><br>";

}
closedir($dh);
?>
The problem is you're looping through a function declaration. So only the last function is ever used. What you need is to declare the function somewhere separate and have the file passed to it. For instance:[code]<script type="text/javascript">
function openwindow(filename)
{
window.open("editor.php?filename="+filename, "mywindow", "menubar=0,resizable=0,width=850,height=550,location=1");
}
</SCRIPT>

while (($file = readdir($dh)) !== false) {
if($file == '.' || $file == '..')
{
continue;
}
echo "<input type='button' value='EDIT' onClick=\"openwindow('$file')\"><br>";
}[/code] Notice I removed the / at the beginning of editor.php as that would have pointed to a file in your base directory. Also, it's now openwindow($file) to work with the function.
lol, I wish I could make it easy for you, or anyone. When I put it there, before the loop, nothing happens. Then I take a look at the console and it says that it is undefined.

Do you have AIM/MSN/or Yahoo!?
It would be faster to talk...



code:




<?php
if($path == 1){
$file=$_GET['file'];
$path = "../htdocs/$file";
}else {
$path = "../htdocs/";
}
$i = 0;
?>
<script language=\"JavaScript1.2\">
function openwindow()
{
window.open("editor.php?filename=$file", "mywindow", "menubar=0,resizable=0,width=850,height=550,location=1");
}
</SCRIPT>
<?php
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
$i = $i + 1;

echo "<input type=text name='filename' value='$file'> <input type='submit' value='EDIT' onClick='openwindow()'><br>";

}
closedir($dh);
?>
My profile contains my MSN and AIM(which I never use) information if you want it but I'm pretty sure your problem is that you missed:

<script type="text/javascript">
function openwindow([!--coloro:red--][span style=\"color:red\"][!--/coloro--]filename[!--colorc--][/span][!--/colorc--])
{
window.open("editor.php?filename="[!--coloro:red--][span style=\"color:red\"][!--/coloro--]+filename[!--colorc--][/span][!--/colorc--], "mywindow", "menubar=0,resizable=0,width=850,height=550,location=1");
}
</script>

and further on...

echo "<input type=text name='filename' value='$file'> <input type='submit' value='EDIT' onClick=\"openwindow([!--coloro:red--][span style=\"color:red\"][!--/coloro--]'$file'[!--colorc--][/span][!--/colorc--])\"><br>";
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.