Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Drop down menu...help :'(

    hey guys,

    I have been trying to put an menu option on a form, with 3 options in it.

    Then i need 3 scripts that will upload an image to the server (php) ((no problem))

    However, i want each script to be linked with the option in the drop down list.

    I.E.. Browse to select me.jpg, then select upload to: album1, or album2, or album 3 (depending on users choice) then it will put the relevent script.php in the <form action=" "

    A little birdie told me that this may be possible using javascript, however my js is not advanced enough to know how..

    Does anybody have any ideas if this is possible with JS, and if so, how would i go about coding it?

    Any help is more than apreciated, thanks

    Jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    fred='Album1';
    /*]]>*/
    </script></head>
    
    <body>
    
    <form action="http://wwww.What'+fred+'ever.php" >
    <select onchange="fred=this.value;" >
    <option value="Album1" >Album 1</option>
    <option value="Album2" >Album 2</option>
    <option value="Album3" >Album 3</option>
    </select>
    
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    hi mate,

    thanks very much for you help.

    Could you explain your code a bit though as im not sure if i understand all of it?

    Thanks

    jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    <form action="http://wwww.What'+fred+'ever.php" >
    <select onchange="fred=this.value;" >
    <option value="Album1" >Album 1</option>
    <option value="Album2" >Album 2</option>
    <option value="Album3" >Album 3</option>
    </select>

    the onchange event changes the value of variable fred to the selected option value

    the url uses the variable fred to costruct the text of the url
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    that makes sense to me now, however, i cant get it to work

    have i used your code correctly here:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>FartingFish.com - the online photo album</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    fred='skatingupload';
    /*]]>*/
    </script>
    
    </head>
    <body>
    
    <div id="container">
    		<div id="logo">
    			<img src="logo_main.jpg" alt="mail logo">
    		</div>
    
    <div id="menu">
      	<ul>
        	<li><a href="index.php">Home</a></li>
        	<li><a href="skating.php">Ice Skating</a></li>
        	<li><a href="pool.php">Pool</a></li>
        	<li><a href="random.php">Random Images</a></li>
        	<li><a href="video.php">Videos</a></li>
        	<li><a href="upload_image.php">Upload an Image</a></li>
    	<li><a href="#">Contact Me</a></li>
      	</ul>
    </div>
    <br>
    <br>
    <div id="description">
    	<i>Welcome to the upload section of the Photo Album, here you can
    		can upload your photo's. Please feel free to upload your images
    		for everyone to view.</i>
    </div>
    <br>
    <form action="http://wwww.fartingfish.com/'+fred+'.php" method="post" enctype="multipart/form-data">
    	<div id="form">
    
    		<label class="boldital" for="file">Image:</label>
    		<input type="file" name="file" id="file">
    		<br>
    		<br>
    		<b><i>Which album would you like to upload your image to?</i></b>
    		<br>
    		<select onchange="fred=this.value;" >
    			<option value="skatingupload" >Ice Skating</option>
    			<option value="poolupload" >Pool</option>
    			<option value="upload" >Random Images</option>
    		</select>
    
    		<br>
    		<br>
    		<input type="submit" id="upload" name="upload" value="Upload">
    	</div>
    <br>
    
    
    </div>
    </body>
    </html>
    Thanks again

    jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    anyone got any ideas??

    Jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P

  • #7
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    this should be better
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>FartingFish.com - the online photo album</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function ChangeAction(obj){
     obj.form.action='http://www.fartingfish.com/'+obj.value+'.php';
    }
    
    /*]]>*/
    </script>
    
    </head>
    <body>
    
    <div id="container">
    		<div id="logo">
    			<img src="logo_main.jpg" alt="mail logo">
    		</div>
    
    <div id="menu">
      	<ul>
        	<li><a href="index.php">Home</a></li>
        	<li><a href="skating.php">Ice Skating</a></li>
        	<li><a href="pool.php">Pool</a></li>
        	<li><a href="random.php">Random Images</a></li>
        	<li><a href="video.php">Videos</a></li>
        	<li><a href="upload_image.php">Upload an Image</a></li>
    	<li><a href="#">Contact Me</a></li>
      	</ul>
    </div>
    <br>
    <br>
    <div id="description">
    	<i>Welcome to the upload section of the Photo Album, here you can
    		can upload your photo's. Please feel free to upload your images
    		for everyone to view.</i>
    </div>
    <br>
    <form action="http://www.fartingfish.com/skatingupload.php" method="post" enctype="multipart/form-data">
    	<div id="form">
    
    		<label class="boldital" for="file">Image:</label>
    		<input type="file" name="file" id="file">
    		<br>
    		<br>
    		<b><i>Which album would you like to upload your image to?</i></b>
    		<br>
    		<select onchange="ChangeAction(this);" >
    			<option value="skatingupload" >Ice Skating</option>
    			<option value="poolupload" >Pool</option>
    			<option value="upload" >Random Images</option>
    		</select>
    
    		<br>
    		<br>
    		<input type="submit" id="upload" name="upload" value="Upload">
    	</div>
    <br>
    
    
    </div>
    </form>
    </body>
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #8
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts


    Works perfect mate

    Only other thing thats niggling me with it is the upload scripts i have wont upload to both directories as it thought they would, i know its php and im in the js forum, but i thought maybe you are an expert in many fields!

    Here goes, this is what i have:

    Code:
    <?php
    
    $uploaddir="gallery";
    $uploaddirl="largegallery";
    
    if (is_uploaded_file($_FILES['file']['tmp_name']))
    {
    move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
    move_uploaded_file($_FILES['file']['tmp_name'],$uploaddirl.'/'.$_FILES['file']['name']);
    }
    print "Image Uploaded Successfully"
    
    ?>
    my assumption was that if i add another var with another directory and then moved the file twice it would save the file to 2 directories??

    After realising it doesent work, i thought maybe the tmp file is deleted as soon as its moved once? is there a way of saving it to 2 directories?

    Thanks again

    Jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •