TonyReba
asked on
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?
$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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry I forgot to ask you, how about the php variable with the course title?
ASKER
$training= "Customer Service";
Not sure I follow, could you explain better :)
ASKER
This variable:
<?php
$training= "Customer Service";
?>
Can this appear on the popup message, also?
<?php
$training= "Customer Service";
?>
Can this appear on the popup message, also?
ASKER