PDA

View Full Version : Using JavaScript Drop Down menu to call PHP Script



Ziggie
08-13-2005, 08:07 AM
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.


<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>

Ziggie
08-14-2005, 06:08 AM
Bump

<cough cough>

150563
05-31-2007, 06:37 AM
Did you ever get a response to this? I am interested to know as part of what you are after would help me.

codeexploiter
05-31-2007, 09:05 AM
Try the following 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.

Ziggie
05-31-2007, 05:02 PM
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?

:confused: :D :rolleyes:

Bob90
05-31-2007, 09:58 PM
Over 1 and a half years - LOL, just LOL.