• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

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

0
TonyReba
Asked:
TonyReba
  • 4
  • 2
1 Solution
 
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
 
TonyRebaAuthor Commented:
thanks!
0
 
TonyRebaAuthor Commented:
Sorry I forgot to ask you, how about the php variable with the course title?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now