PDA

View Full Version : help with dropdown values


elementis0
12-08-2007, 05:18 AM
Hello, I am designing a website and have run into a problem.
I have a webpage form that has dropdown boxes. each dropdown box has a value of its webpage.
what i need is a simple javascript function that takes the value from whatever has just been selected and to insert it into a different area of the form.


<html>
<head>
<script type="text/javascript">
function checkform()
{
if (document.page_edit.page_name.value == 'null')
{
alert('You have not selected a webpage to edit.');
return false;

}
}
</script>
</head>
<body>
<form action="pagepreview.php" onSubmit="return checkform()" name="page_edit" method="post">
<table style="width:100%;">
<tr>
<td>Which WebPage Would You Like to Edit?</td>
</tr>
<tr>
<td>
<select name="page_name" onchange="alert(this.options[this.selectedIndex].value)">
<option value="null" selected="selected">---</option>
<optgroup label="Home">
<option value="index.php">Homepage</option>
</optgroup>
<optgroup label="Festivals">
<option value="safevent.php">Spring Arts Festival</option>
<option value="ffevent.php">Flower Festival</option>
</optgroup>
<optgroup label="Events">
<option value="chilicookevent.php">Chili Cook-Off</option>
<option value="bbqshootevent.php">BBQ Shoot-Out</option>
<option value="carshowevent.php">Car Show</option>
<option value="paradeevent.php">Parade</option>
<option value="flowershowevent.php">Flower Show</option>
</optgroup>
<optgroup label="Applications">
<option value="artsandcraftsapp.php">Arts and Crafts</option>
<option value="chilicookapp.php">Chili Cook-Off</option>
<option value="bbqshootapp.php">BBQ Shoot-Out</option>
<option value="paradeapp.php">Parade</option>
<option value="2008queenapp.php">2008 Queen</option>
<option value="commercialapp.php">Commercial Center</option>
<option value="entertainmentapp.php">Entertainment</option>
<option value="sponsorshipsapp.php">Sponsorships</option>
</optgroup>
<optgroup label="Rules">
<option value="safrules.php">Spring Arts Festival</option>
<option value="ffrules.php">Flower Festival</option>
</optgroup>
<optgroup label="Rules">
<option value="entertainmentabout.php">Entertainment</option>
<option value="foodabout.php">Food</option>
</optgroup>
<optgroup label="Misc.">
<option value="hours.php">Hours</option>
<option value="maps.php">Maps</option>
<option value="bod.php">Board of Directors</option>
<option value="history.php">History</option>
<option value="sponsors.php">Sponsors</option>
<option value="contact.php">Contact</option>
<option value="links.php">Links</option>
</optgroup>
</select></td>
</tr>
<tr align="center">

<td colspan="2"><br />Write Webpage Content:</td>
</tr>
<tr>
<td colspan="2">
<textarea style="width:100%; height:600px;" name="parseit">
<?php
$con = mysql_connect('hide','hide', 'hide');
mysql_select_db('flower_festival',$con);
$query = mysql_query("SELECT content FROM site_content WHERE page_name='".I want to put the selected value here."'");
while($content = mysql_fetch_array($query))
{
echo $content['content'];
}
mysql_close($con);
?>
</textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update Page" name="submit" />
</td>
</tr>
</table>
</form>
</body>
</html>


To be more specific, I want the currently selected value in the dropdown to be displayed in the textarea. Whenever the value is changed in the dropdown the textarea should be refreshed with the new variable value which should in turn also refresh the mysql query.
I think to achieve this, the javascript function might have to have to make a variable the contains the currently selected value to pass to a php variable that is usable in the mysql query. but i am not sure about that idea.

I would greatly appreciate anybody here that can devise a JS function to do this.

Thank you.

Fang
12-08-2007, 01:23 PM
To refresh the mysql query you have to submit the form. This is server side processing.
Once that works you could consider using Ajax for submission and update.