JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 19th, 2012, 09:35 AM
scdawg scdawg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 1 scdawg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 4 sec
Reputation Power: 0
Other - Trouble passing variables to popup from php while loop

I have a while loop that displays all files associated with a project that display in a table. A project can have one file or 100 associated. I want to use a button to open those files in a popup. My problem is that all the buttons, open the same file instead of their respective files, which is the first file displayed(the variables passed to the popup never change). If I do use a simple link (href) in the php code, I can open the correct file, but it doesn't display in a popup, it opens in the same window which is a problem. Does anyone have any suggestions on how to use a link or button to open the correct files in a popup? Below is my code:

Code:

While(list($date, $filename, $title) =  mysql_fetch_array($resultd)) {

echo
"<tr>\n".
"<td align=center>$date</td>\n".
"<td align=center>$title</td>\n".
"<td align=center><a href='docs/$coid/$filename'>$filename</a></td>\n".
"<td align=center><input type='hidden' value='$filename' name='file_name'></input></td>\n";
?>

<td align="center"><input type="button" value="View Document" onclick="return viewdoc(); return false">
<?
echo

"<td align=center><input type='button' value='Delete Document' name='file_delete'></input></td>\n".
"</tr>\n";
}

echo
"</table>\n".
"<br><br><INPUT TYPE='submit' NAME='submit' VALUE='Submit'></p>\n".
"<input type='hidden' name='comp_id' value='$coid'>\n".
"</FORM>\n".
"</BODY>\n".
"</HTML>\n";

?>

<script type="text/javascript" language="javascript">
<!-- Document open

function viewdoc() {
var filename = document.getElementById("file_name").value;
var compid = document.getElementById("comp_id").value;

newwindow = window.open('/'+'docs/'+compid+ '/' +filename,'DocViewer','width=800,height=600,top=150,left=350,scrollbars=1,status=1');
if (window.focus) {newwindow.focus()}
	return false;
}

Reply With Quote
  #2  
Old September 19th, 2012, 06:01 PM
jack13580 jack13580 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 154 jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 11 h 1 m 16 sec
Reputation Power: 75
there is a lot of errors in your code



first you should make the capitol W for you while loop lowercase, second make all your html attributes lowercase, third in your a href add target="_blank", next with
Code:
<!-- Document open
you need to end it like this
Code:
<!-- Document open -->
, next you don't need to end things in javascript with ;, and to get the value of a hidden field use
Code:
document.formName.elements['abcName'].value
where formName is the forms name and abcName is the hidden fields name

Reply With Quote
  #3  
Old September 19th, 2012, 06:20 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,890 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 2 Days 17 h 55 m 47 sec
Reputation Power: 4192
Quote:
Originally Posted by jack13580
you don't need to end things in javascript with ;

While it's not required, it's best practice to do so.

Quote:
Originally Posted by jack13580
Code:
document.formName.elements['abcName'].value

Actually, it's better to use this:
Code:
document.forms.formName.elements['abcName'].value

or
Code:
document.forms['formName'].elements['abcName'].value
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
  #4  
Old September 19th, 2012, 07:08 PM
jack13580 jack13580 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 154 jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level)jack13580 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 11 h 1 m 16 sec
Reputation Power: 75
Kravvitz is correct

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Other - Trouble passing variables to popup from php while loop

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap