www.webdeveloper.com
Results 1 to 4 of 4

Thread: can i integrate a PHP code in a JavaScript code?

  1. #1
    Join Date
    Mar 2009
    Posts
    5

    can i integrate a PHP code in a JavaScript code?

    Hi ,

    I am stuck with a problem ....

    Can i integrate a PHP code in a JavaScript code ?

    for example in this codei want to incorporate these options(MIM,MICE) from a database in this JavaScript code ?


    <html>
    <head>
    <title>Dual Selections</title>
    <script type="text/javascript">


    var a = ['|-- Please Select --','|MIM','|MICE']; // automatic value assignments
    var b = ['|-- Please Select --','123|IGI','456|ERE']; // demonstration of value assignments

    function choice(IDS,t){
    s = document.getElementById(IDS);
    for(var i = s.options.length; i >= 0 ; i--) { s.options[i] = null; }
    if(t != 0){
    var z = [];
    switch (t) {
    case '1' : z = a; break;
    case '2' : z = b; break;
    default : alert('Invalid entry: '+IDS+' : '+t+'\n\n'+z); break;
    }
    var tmp = [];
    for(i = 0; i < z.length; i++ ) {
    tmp = z[i].split('|')
    if (tmp[0] == '') { tmp[0] = tmp[1]; }
    s.options[i] = new Option(tmp[1],tmp[0],false,false);
    }
    }
    }
    </script>
    </head>
    <body>

    <SELECT id="INSTITUTE" onChange="choice('CHAIN',this.value)">
    <option value="0">-- Please Select --</option>
    <option value="1">ISIMS</option>
    <option value="2">ISGI</option>
    </SELECT>

    <!-- onChange below only for testing purposes -- not needed -->
    <SELECT id="CHAIN" onChange="alert('Value: '+this.value)"></SELECT>
    </body>
    </html>

    So please help me.

  2. #2
    Join Date
    Mar 2009
    Location
    Washington
    Posts
    19
    Quote Originally Posted by chahbandar View Post
    Can i integrate a PHP code in a JavaScript code?
    Absolutely you can!

    For Example:
    HTML Code:
    <script type="text/javascript">
    var arr = new Array("<?=$someValue?>", "<?=$someValue2?>");
    </script>
    Last edited by mackil; 03-19-2009 at 10:36 AM.

  3. #3
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    Just remember you will need to get the values for mackil's example before adding them to the javascript code.

  4. #4
    Join Date
    Apr 2007
    Posts
    1,664
    You can do it after too with ajax.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles