SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing option data in javascript's confirm message from php

    hello....

    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="1">Rashmita</option>
    <option value="2">Sujit</option>
    <option value="3">Itishree</option>
    <option value="4">Mitali</option>
    </select>

    <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;
    }
    //else
    }
    </script>

    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..

  2. #2

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be very easier if you use jQuery. Following normal JS will work for you:
    Code javascript:
    var ele = document.getElementById('to_id');
    var val = ele.options[ele.selectedIndex].text;
    alert(val);
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Use .text instead of .value
    Hi cpradio,

    Are you sure just using .text will work instead of .value? Can you please show the example?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Changing
    Code:
    var start = document.forward_file.to_id.value;
    To
    Code:
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •