How do I display the selected value of a select box in javascript

I built a php page which shows a dropdownlist with a list of dates which are pulled from a database on mysql , so I have a select box  called dateSelectBox  and a button proceedButton . Also I  have a variable called training date as
$training ="Customer Service";
and I want to be able to  show a confirmation message (javascript) which will alert the user , to enroll for that training or cancel.

The popup should say :

confirm(""Are you sure you want to enroll for $training  on dateSelectBox?");

How can I do this in my current code?

<script language="JavaScript">
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to enroll for ?");
if (agree)
      return true ;
else
      return false ;
}
</script>

 

<script>
var what = {
  "date": "<? echo $dateSelectBox; ?>";
}

</script>


if ($_POST['proceedButton'] != '') {

$user =& JFactory::getUser();
$user_id = $user->id;

$user_dept = $user->department;

$department =& JFactory::getUser($user_dept);


$user = JFactory::getUser(); 
$training= "Customer Service";
$id = $user->get('id'); 
$name = $user->get('name');
$username = $user->get('username'); 
//$department = $user->get('department');

$vardate = date("Y-m-d H:i:s");



$vartrainingID = $_POST['dateSelectBox'];

/***************************************/

$db = &JFactory::getDBO();

$query = "
INSERT INTO
`jos_jquarks_persontraining`
(

training_id,user_id,employeeNumber,department,name,timeStamp)
VALUES
(

'{$vartrainingID}',

'{$id}',
'{$username}',
'{$user_dept}',
'{$name}',
'{$vardate}'
)";

$db->setQuery($query);

$db->query();

if($db->getErrorNum()) { 
//JError::raiseError( 500, $db->stderr());

mysql_close($db);

header("Location: index.php?option=com_content&view=article&id=28");
exit();

} 

else {

header("Location: index.php?option=com_content&view=article&id=27");
exit();
}

}

?>

<form name="quiz_info" method="post" onSubmit="return validate(this)" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

<?php

echo JText::_('Please select the date:');

$database= &JFactory::getDBO();

$database->setQuery('SELECT training_id,CONCAT(date_format(trainingDate,"
%W, %M %e, %Y"),"-",trainingHour) AS trainingDates FROM training WHERE openSeats > 0 ORDER BY trainingDate ASC ,training_id');

$result = $database->loadObjectList();


echo '<select name="dateSelectBox">';
foreach ($result as $row) {

echo '<option value="'.$row->training_id.'" text="'.$row->trainingDates.'">'.$row->trainingDates.'</option>';
}
echo '</select>';

?>

<input id="proceedButton" name="proceedButton" value="Enroll" type="submit" onClick="return confirmSubmit()" />
</form>

Open in new window

LVL 9
TonyRebaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Greg AlexanderLead DeveloperCommented:
Here you go

<script language="JavaScript">
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to enroll for "+document.getElementById('dateSelectBox').value+"?");
if (agree)
      return true ;
else
      return false ;
}
</script>

 

<script>
var what = {
  "date": "<? echo $dateSelectBox; ?>";
}

</script>


if ($_POST['proceedButton'] != '') {

$user =& JFactory::getUser();
$user_id = $user->id;

$user_dept = $user->department;

$department =& JFactory::getUser($user_dept);


$user = JFactory::getUser(); 
$training= "Customer Service";
$id = $user->get('id'); 
$name = $user->get('name');
$username = $user->get('username'); 
//$department = $user->get('department');

$vardate = date("Y-m-d H:i:s");



$vartrainingID = $_POST['dateSelectBox'];

/***************************************/

$db = &JFactory::getDBO();

$query = "
INSERT INTO
`jos_jquarks_persontraining`
(

training_id,user_id,employeeNumber,department,name,timeStamp)
VALUES
(

'{$vartrainingID}',

'{$id}',
'{$username}',
'{$user_dept}',
'{$name}',
'{$vardate}'
)";

$db->setQuery($query);

$db->query();

if($db->getErrorNum()) { 
//JError::raiseError( 500, $db->stderr());

mysql_close($db);

header("Location: index.php?option=com_content&view=article&id=28");
exit();

} 

else {

header("Location: index.php?option=com_content&view=article&id=27");
exit();
}

}

?>

<form name="quiz_info" method="post" onSubmit="return validate(this)" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

<?php

echo JText::_('Please select the date:');

$database= &JFactory::getDBO();

$database->setQuery('SELECT training_id,CONCAT(date_format(trainingDate,"
%W, %M %e, %Y"),"-",trainingHour) AS trainingDates FROM training WHERE openSeats > 0 ORDER BY trainingDate ASC ,training_id');

$result = $database->loadObjectList();


echo '<select name="dateSelectBox" id="dateSelectBox">';
foreach ($result as $row) {

echo '<option value="'.$row->training_id.'" text="'.$row->trainingDates.'">'.$row->trainingDates.'</option>';
}
echo '</select>';

?>

<input id="proceedButton" name="proceedButton" value="Enroll" type="submit" onClick="return confirmSubmit()" />
</form>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TonyRebaAuthor Commented:
thanks!
0
TonyRebaAuthor Commented:
Sorry I forgot to ask you, how about the php variable with the course title?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

TonyRebaAuthor Commented:
$training= "Customer Service";
0
Greg AlexanderLead DeveloperCommented:
Not sure I follow, could you explain better :)
0
TonyRebaAuthor Commented:
This variable:
<?php
$training= "Customer Service";

?>

Can this appear on the popup message, also?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.