Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textfield id auto insert

Status
Not open for further replies.

artisstcollier

Programmer
Dec 15, 2007
2
US
I am currently trying to find a way to modify a short snippet of code that opens a child popup window, and when a link is selected, that link path is inserted in a textfield with an id on the parent page.

I am trying to use 4 textfields, each with its own unique id but can't get it to work by copying and pasting the code 3 times and supplementing each id with the cooresponding textfield.

The following is the snippet:
Code:
<script type="text/javascript">
function WantThis(url) {
 window.opener.document.getElementById('if_url').value = url;
 window.close();
}
</script>
The textfield is:

<input type="text" name="header" id="if_url"" size="5">

This works fine but I need it to work with 3 more textfields such as:

<input type="text" name="header" id="if_tnav" size="5">
<input type="text" name="header" id="if_lnav" size="5">
<input type="text" name="header" id="if_rnav" size="5">

Any help would be appreciated.
 
I am currently trying to find a way to modify a short snippet of code that opens a child popup window, and when a link is selected, that link path is inserted in a textfield with an id on the parent page.

I am trying to use 4 textfields, each with its own unique id but can't get it to work by copying and pasting the code 3 times and supplementing each id with the cooresponding textfield.

The following is the snippet:

Code:
<script type="text/javascript">
function WantThis(url) {
 window.opener.document.getElementById('if_url').value = url;
 window.close();
}
</script>

The relevant javascript code within the php file is:

Code:
<?php
$self = $_SERVER['SCRIPT_NAME'];
$docpath = $_REQUEST['d'] ? $_REQUEST['d'] : '/template-images';
$d = $_SERVER['DOCUMENT_ROOT'] . '/' . $docpath;
$d = str_replace('//','/',$d);
if (!is_dir($d)) $d = $_SERVER['DOCUMENT_ROOT'];
$dir = opendir($d);
while ($file = readdir($dir)){
  $files[] = $file;
}
closedir($dir);
usort($files, "insensitive"); //see function insensitive($a, $b)
foreach ($files as $filename) {
  $filepath = "$d/$filename";
  $fsize = sprintf("%u", filesize($filepath)); //filesizes over 2Mb won't fit in an int so we unsign it
  $modtime = date ("d F Y H:i:s", filemtime($filepath)); //mtime is unix timestamp
  $tip = " Size: $fsize <br>Updated: $modtime ";
  if (is_dir($filepath)) { //it's a directory
    if ($filename == '.'){ //current directory
      $dlist .= "<img src='[URL unfurl="true"]http://www.genesites-hosting.com/whizzery/buttons/dir.gif'>[/URL] $docpath ";
    } else if ($filename == '..') { //parent directory
      if($docpath) { //we're in a sub directory - no Up from root
        $updir = substr($docpath,0,strrpos($docpath,'/'));
        $dlist .= "<img src='[URL unfurl="true"]http://www.genesites-hosting.com/whizzery/buttons/back.gif'><a[/URL] href='$self?d=$updir'>Up</a>/<br>";
       }
    } else if ($filename != 'bak') {
      $docpath = str_replace($_SERVER['DOCUMENT_ROOT'], "", $d);
      $dlist .= "<img src='[URL unfurl="true"]http://www.genesites-hosting.com/whizzery/buttons/dir.gif'><a[/URL] href='$self?d=$docpath/$filename'>$filename</a>/<br>"; 
    }
  } else if (strpos($filename, '.jpg') || strpos($filename, '.gif') || strpos($filename, '.png') || strpos($filename, '.ico') ) {
      $flist .= "<img src='[URL unfurl="true"]http://www.genesites-hosting.com/whizzery/buttons/image.gif'><a[/URL] href='#' onclick='WantThis(\"$docpath/$filename\")' onmouseover='document.getElementById(\"preview\").src=\"$docpath/$filename\";document.getElementById(\"caption\").innerHTML=\"<b>$filename</b><br>$tip\"'>$filename</a></br>"; //it's a picture
 }

}
echo $dlist . $flist;

function insensitive($a, $b) { //used by usort to sort file list case insensitive -------------------------
   return strcmp(strtolower($a), strtolower($b));
}
?>

The textfield is:

<input type="text" name="header" id="if_url"" size="5">

This works fine but I need it to work with 3 more textfields such as:

<input type="text" name="header" id="if_tnav" size="5">
<input type="text" name="header" id="if_lnav" size="5">
<input type="text" name="header" id="if_rnav" size="5">

Any help would be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top