javascript within php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maminx
    New Member
    • Jul 2008
    • 77

    javascript within php

    hello all, i have a question..can script of javascript (variable of js or html form)stored within tag php or php command???

    thanks


    kind regards, maminx
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Give an example of what you mean.

    Comment

    • maminx
      New Member
      • Jul 2008
      • 77

      #3
      Originally posted by r035198x
      Give an example of what you mean.

      the point is i need to call a javascript method within php code, but with no user interaction. i.e. no click of a button, no user input, nothing.


      this is the example

      i have an input form

      [HTML]<input name="textfield " type="text" size="10" value="<?php echo $this->ProjectPraBp_m odel->getProjectPraB pDate("025");?>">
      [/HTML]

      there's value "025" (bold)...i want that value is from javascript variable / form html object, is it possible??

      thanks

      maminx
      Last edited by gits; Jul 29 '08, 08:01 AM. Reason: remember to use CODE tags !!!!

      Comment

      • maminx
        New Member
        • Jul 2008
        • 77

        #4
        Originally posted by maminx
        the point is i need to call a javascript method within php code, but with no user interaction. i.e. no click of a button, no user input, nothing.


        this is the example

        i have an input form

        [HTML]<input name="textfield " type="text" size="10" value="<?php echo $this->ProjectPraBp_m odel->getProjectPraB pDate("025");?>">
        [/HTML]

        there's value "025" (bold)...i want that value is from javascript variable / form html object, is it possible??

        thanks

        maminx

        is there anyone can help me with this issue??

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          This won't be possible directly. PHP is server-side. It runs and the page finishes execution whereas JavaScript is client-side.

          The way to solve your problem would be to make an Ajax request after the page loads with the JavaScript variable. However, having said that, if you already know the JavaScript value, just replace it in the PHP code.

          Comment

          • maminx
            New Member
            • Jul 2008
            • 77

            #6
            Originally posted by acoder
            This won't be possible directly. PHP is server-side. It runs and the page finishes execution whereas JavaScript is client-side.

            The way to solve your problem would be to make an Ajax request after the page loads with the JavaScript variable. However, having said that, if you already know the JavaScript value, just replace it in the PHP code.

            yes i think it needs ajax, and of i of course i don;t know the javascript value so i can't replace it with the php code..the value is generated with html form or variable of javascript..

            But my issue now is because i'm using framework php (codeigniter), than i can't just put the ajax into the php code, there's a rule of framework..

            anyway, thanks a lot

            kind regards, maminx

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              It must allow some JavaScript which you can put in the head and call when required, e.g. onclick of a button.

              If that's not possible, submit the form with a hidden value and set the input value using PHP.

              Comment

              Working...