The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Using dropdowns, Need help in coding
slovey
post Mar 28 2015, 03:49 PM
Post #1





Group: Members
Posts: 7
Joined: 28-March 15
Member No.: 22,432



I want to use a dropdown list to allow users to select a month and then want to use that as part of the name of a pdf file to display

Here is what I have so far but it doesn't work

<select CMON>
<option>Mar</option>
<option>Feb</option>
<option>Jan</option>
</select>
<script>
If $CMON = "Mar"
<A "href=SL_Mar.pdf"></A>
else
if $CMON = "Feb"
<A "href=SL_Feb.pdf"></A>
else
if $CMON = "Jan"
<A "href=SL_Jan.pdf"></A>
</script>


thanks in advance for your help
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 28 2015, 10:21 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Well, your select example in not valid HTML. See this link: 'http://www.tizag.com/htmlT/htmlselect.php'. You don't need 12 if statements, as long as 'SL_' and '.pdf' are always the same. Use the select value in your function call to build the file name. Are you trying to use PHP or Javascript. Since PHP doesn't use <script> tags I will assume you want to use Javascript, even if it does look like you are using a PHP variable. Do some searching and if you need help then post your code and show where the problem is.

This post has been edited by CharlesEF: Mar 28 2015, 10:22 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 29 2015, 11:03 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(CharlesEF @ Mar 29 2015, 05:21 AM) *

Since PHP doesn't use <script> tags I will assume you want to use Javascript, even if it does look like you are using a PHP variable.

As a sidenote/nitpick, PHP actually can use something like

CODE
<script language="php">
// PHP code here
</script>

but then you must use the LANGUAGE attribute for the server's PHP engine to recognize it (a <script> tag without the LANGUAGE attribute defaults to javascript in HTML5). See also example 2: http://php.net/manual/en/language.basic-syntax.phpmode.php
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 30 2015, 12:47 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(Christian J @ Mar 29 2015, 11:03 AM) *

QUOTE(CharlesEF @ Mar 29 2015, 05:21 AM) *

Since PHP doesn't use <script> tags I will assume you want to use Javascript, even if it does look like you are using a PHP variable.

As a sidenote/nitpick, PHP actually can use something like

CODE
<script language="php">
// PHP code here
</script>

but then you must use the LANGUAGE attribute for the server's PHP engine to recognize it (a <script> tag without the LANGUAGE attribute defaults to javascript in HTML5). See also example 2: http://php.net/manual/en/language.basic-syntax.phpmode.php

Learned something new today. biggrin.gif I never had a need to do it that way, but it is nice to know.

Thanks
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slovey
post Mar 30 2015, 09:21 AM
Post #5





Group: Members
Posts: 7
Joined: 28-March 15
Member No.: 22,432



ok, I am getting totally confused between php and javascript. I thought I wanted javascript but I guess either can work. I am confused on how to build the command to display the correct pdf file. Can one of you please just show me the code I need for both the dropdown and the pdf file? Thanks, this is all a little new to me.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 30 2015, 02:11 PM
Post #6


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(slovey @ Mar 30 2015, 04:21 PM) *

ok, I am getting totally confused between php and javascript.

PHP is more robust but requires submitting a form to a new page, where you might let the PHP script redirect to the URL of the selected PDF file.

Javascript can redirect to the PDF file directly, but with decent web host the speed gain should be minimal.

QUOTE
I am confused on how to build the command to display the correct pdf file.

You can load its URL directly, but from there it's up to the browser's settings/capabilities. Some browsers may require an external PDF viewer plugin, others (like newer Firefox) can display PDF files directly in the browser.

Here's a simple example. This is the HTML form page "select.html":

CODE
<form method="post" action="foo.php">
<select name="month">
<option>Mar</option>
<option>Feb</option>
<option>Jan</option>
</select>
<input type="submit" value="Send">
</form>

This is the PHP script "foo.php":

CODE
<?php
// The URL of the form page. The PHP script
// redirects to it if someone loads the script
// directly without submitting the form properly.
$url='http://foo.com/select.html';

if(isset($_POST['month']))
{
    // should return a URL like "http://foo.com/Mar.pdf".
    $url='http://foo.com/'.$_POST['month'].'.pdf';     
}
header("Location:$url");
exit;
?>

(Don't put the PHP script in the same file as the HTML form, since it would result in a redirect loop.)

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slovey
post Mar 31 2015, 05:55 PM
Post #7





Group: Members
Posts: 7
Joined: 28-March 15
Member No.: 22,432



Ok, I did as you said, I make my selection and the browser loads the PHP file below but nothing shows up in the window.
I changed line 5 to show my htm page
and line 10 to show my PDF file name. It is SL_Mar.pdf or what ever month
So where did I mess it up? Thanks in advance
Your help has been fantastic.

<?php
// The URL of the form page. The PHP script
// redirects to it if someone loads the script
// directly without submitting the form properly.
$url='href:Stutest_2.htm';

if(isset($_POST['month']))
{
// should return a URL like "http://foo.com/Mar.pdf".
$url='http:/SL'.$_POST['month'].'.pdf';
}
header("Location:$url");
exit;
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 1 2015, 08:00 AM
Post #8


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(slovey @ Apr 1 2015, 12:55 AM) *

$url='href:Stutest_2.htm';

The above is not a valid URL. You should remove the "href:" part, but it may also be safest to use a full URL (like "http://yourdomain.com/Stutest_2.htm", or similar).

QUOTE
$url='http:/SL'.$_POST['month'].'.pdf';

You need your site's full URL instead of "http:/SL". The above would just result in something like "http:/SLMar.pdf", which is not valid.

See also http://php.net/manual/en/function.header.php (the parts about "Location").
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slovey
post Apr 5 2015, 01:45 PM
Post #9





Group: Members
Posts: 7
Joined: 28-March 15
Member No.: 22,432



I changed to add the full web site but get 405 error
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

used $url='http://loventhal.homeip.net/Public/SL'.$_POST['month']'.pdf';
Help please

This post has been edited by slovey: Apr 5 2015, 01:46 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 5 2015, 03:15 PM
Post #10


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(slovey @ Apr 5 2015, 08:45 PM) *

I changed to add the full web site but get 405 error
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

What does the URL look like in the browser's address bar?

QUOTE
used $url='http://loventhal.homeip.net/Public/SL'.$_POST['month']'.pdf';

There's a period sign missing between

CODE
$_POST['month']

and
CODE
'.pdf'

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slovey
post Apr 6 2015, 06:10 PM
Post #11





Group: Members
Posts: 7
Joined: 28-March 15
Member No.: 22,432



You are all being very patient working with me but I still get the 405 error

Here is HTML code
<H3><B>My Notes</B></H3>
<form method="post" action="PVETest.php">
<select name="month">
<option>Mar</option>
<option>Feb</option>
<option>Jan</option>
</select>
<input type="submit" value="Send">
</form>


Here is PHP file - named PVETest.php
<?php
// The URL of the form page. The PHP script
// redirects to it if someone loads the script
// directly without submitting the form properly.
$url='href:PVEHomeTest.htm';

if(isset($_POST['month']))
{
// should return a URL like "http://foo.com/Mar.pdf".
$url='http://loventhal.homeip.net/Public/SL'.$_POST['month'].'.pdf';
}
header("Location:$url");
exit;
?>

files I want to display are named SL_Mar.pdf, SL_Feb.pdf, SL_Jan.pdf

one more time help please.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Apr 6 2015, 08:23 PM
Post #12


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



405 is Method not allowed. Generally, that means you're trying to POST to a file that the server thinks is a plain file, rather than a program. It sounds like your server is not configured to recognize *.php files as programs.

Another possibility is that it requires PHP files to be set as executable, and your *.php files are not set as executable.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 7 2015, 06:57 AM
Post #13


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(Darin McGrew @ Apr 7 2015, 03:23 AM) *

405 is Method not allowed. Generally, that means you're trying to POST to a file that the server thinks is a plain file, rather than a program. It sounds like your server is not configured to recognize *.php files as programs.

Another possibility is that it requires PHP files to be set as executable, and your *.php files are not set as executable.

Maybe it's best to ask the webhost if PHP is supported at all, and if so in which way.

As a sidenote this is still incorrect:

CODE
$url='href:PVEHomeTest.htm';

but it shouldn't affect normal form submissions.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slovey
post Apr 8 2015, 01:07 PM
Post #14





Group: Members
Posts: 7
Joined: 28-March 15
Member No.: 22,432



Okay, got further now

FastCGI Handler was unable to process the request
error number 193 (0x8000700c1)
http error 500-server error

I am looking into that problem now. Thanks for you help
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 26th April 2024 - 09:25 AM