Results 1 to 6 of 6

Thread: Using JavaScript Drop Down menu to call PHP Script

  1. #1
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Using JavaScript Drop Down menu to call PHP Script

    I've never tried anything like this before, and I'm not even sure if it's possible, but here's what I'm trying to do. I am trying to setup a contact/feedback form that allows for one form but users will choose who they want to contact from a javascript drop down menu. I would like the selection they make to determine which PHP script that is called when the submit button hits.

    Here's what I have so far, but I get a crash and burn every time I try (and yes, the PHP files are active, valid, and run if I don't use the javascript menu)

    I have (embarassingly, looking at my code) tried to incorporate this, but I have made such a mess out of things.

    Code:
    <html><body>
    <form name="jump">
    <p align="center">
    &nbsp;<select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">
    <option selected>--Select One--</option>
    <option value="<form action="php/editor.php" method="post">Editor in Chief</option>
    <option value="<form action="php/webmaster.php" method="post">Webmaster</option>
    <option value="<form action="php/artist.php" method="post">Web Artist</option>
    </select></p>
    </form>
    <div align="center">
    <table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
    <tr><td>Name:</td><td><input type="text" name="name" size="25" /></td></tr>
    <tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>
    <tr>
    <td colspan="2">
    Message<br />
    <textarea rows="15" cols="45" name="comments">
    </textarea>
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <input type="submit" value="Send Feedback" /><br />
    </td>
    </tr>
    </table>
    </div>
    </form>
    </script>
    </body></html>

  2. #2
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Bump

    <cough cough>

  3. #3
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Did you ever get a response to this? I am interested to know as part of what you are after would help me.

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following code
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<title>Testing..</title>
    		<script type='text/javascript'>
    			function submitForm() {
    				var form = document.forms["jump"];
    				var selValue = form.menu.options[form.menu.selectedIndex].value;
    				form.action = selValue;
    				form.submit();
    			}
    		</script>
    	</head>
    	<body>
    		<form name="jump" action="" method="post">
    			<p align="center">
    				<select name="menu">
    					<option selected>--Select One--</option>
    					<option value="php/editor.php">Editor in Chief</option>
    					<option value="php/webmaster.php">Webmaster</option>
    					<option value="php/artist.php">Web Artist</option>
    				</select>
    			</p>
    			<div align="center">
    				<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
    					<tr><td>Name:</td><td><input type="text" name="name" size="25" /></td></tr>
    					<tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>
    					<tr><td colspan="2">Message<br /><textarea rows="15" cols="45" name="comments"></textarea></td></tr>
    					<tr><td align="center" colspan="2"><input type="button" value="Send Feedback" onclick='submitForm();'/><br /></td></tr>
    				</table>
    			</div>
    		</form>
    	</body>
    </html>
    Make sure that the server-side pages are existing in the correct path. Moreover I haven't done any other client-side validation like whether the fields are empty or not, valid email or not.

    But this code will invoke the server-side script based on the selection made by the user while submitting the feedback.

  5. #5
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well...that looks like it should work.

    Now, does anyone have a time machine so I can go back and ask myself what I was planning with said code?


  6. #6
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default

    Over 1 and a half years - LOL, just LOL.

Bookmarks

Posting Permissions

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