Passing option data in javascript's confirm message from php


my problem is i want to send the option data in confirm message of javascript from php.

my code is:

<select name=“to_id” id=“to_id”>
<option value=“0”>-----Select Employee------</option>
<option value=“2”>Sujit</option>
<option value=“3”>Itishree</option>
<option value=“4”>Mitali</option>

<script type=“text/javascript”>
function Confirm()
var start = document.forward_file.to_id.value;
var record=confirm("Are you sure you want to send this File to "+start+ “Person??”);
if(record == 1 && start == 0)
alert (‘Please select an Employee name’); return false;
if(record == 1)
return true;
else if(record == 0)
return false;

In this confirm message var start shows the option value i.e. 1,2,3 etc. But, i want to show the name i.e. Rashmita, Sujjit, Mitali etc.

how can it solve, can anyone solve this…
plz its urgent…

Use .text instead of .value

It would be very easier if you use jQuery. Following normal JS will work for you:

var ele = document.getElementById('to_id');
var val = ele.options[ele.selectedIndex].text;

Hi cpradio,

Are you sure just using .text will work instead of .value? Can you please show the example?


var start = document.forward_file.to_id.value;


var start = document.forward_file.to_id.text;

Should work since .value is already working (I could be wrong, but I think I’ve done something like this in the past – although I use jQuery more often than not anymore).

** DISREGARD** Seems, you do have to go through the options[selectedItem].text approach for it to work.