Calling Javascript function in php script.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • IchBin

    #1

    Calling Javascript function in php script.

    Not sure if I should post this to a javascript group or here. So I'll
    try here first since most here mix both in this group. I am trying to
    pass a php value into a JavaScript function that changes the state of a
    particular radio button. The call is:

    setCheckedValue ("abbr_lette r", $_SESSION['abbr_letter'])

    Here is a snip of the code I am trying to get to work. Everything else
    works except for the radio button being set. I just not sure if I have
    things correct.

    Any help would be appreciated.


    session_start() ;
    if(!isset($_SES SION['abbr_letter']))
    $_SESSION['abbr_letter'] = 'A';

    require_once 'includes/config.inc.php' ;
    require_once 'includes/header.inc.php' ;
    //
    // Start a Form
    $cssfile = 'quotes.css';
    ?>
    <html>
    <head>
    <link href="<?php echo $cssfile; ?>" rel="stylesheet "
    type="text/css">
    <SCRIPT LANGUAGE=”JavaS cript”>
    setCheckedValue ("abbr_lette r", $_SESSION['abbr_letter'])

    function setCheckedValue (radioObj, newValue) {
    <?php print("radioObj , newValue: " . radioObj . " . " .
    newValue) ?>
    if(!radioObj)
    return;
    var radioLength = radioObj.length ;
    if(radioLength == undefined) {
    radioObj.checke d = (radioObj.value == newValue.toStri ng());
    return;
    }
    for(var i = 0; i < radioLength; i++) {
    radioObj[i].checked = false;
    if(radioObj[i].value == newValue.toStri ng()) {
    radioObj[i].checked = true;
    }
    }
    }
    </SCRIPT>
    </head>
    <b><FORM NAME="author_ab brv" method="POST" action="<?php echo
    $_SERVER['PHP_SELF'];?>"></b>
    <table>
    <tr>
    <td><input type="radio" name="abbr_lett er" value="A"
    onclick="submit ()"A </td>
    <td><input type="radio" name="abbr_lett er" value="B"
    onclick="submit ()"B </td>
    <td><input type="radio" name="abbr_lett er" value="C"
    onclick="submit ()"C </td>
    <td><input type="radio" name="abbr_lett er" value="D"
    onclick="submit ()"D </td>
    <td><input type="radio" name="abbr_lett er" value="E"
    onclick="submit ()"E </td>
    <td><input type="radio" name="abbr_lett er" value="F"
    onclick="submit ()"F </td>
    <td><input type="radio" name="abbr_lett er" value="G"
    onclick="submit ()"G </td>
    <td><input type="radio" name="abbr_lett er" value="H"
    onclick="submit ()"H </td>
    <td><input type="radio" name="abbr_lett er" value="I"
    onclick="submit ()"I </td>
    <td><input type="radio" name="abbr_lett er" value="J"
    onclick="submit ()"J </td>
    <td><input type="radio" name="abbr_lett er" value="K"
    onclick="submit ()"K </td>
    <td><input type="radio" name="abbr_lett er" value="L"
    onclick="submit ()"L </td>
    <td><input type="radio" name="abbr_lett er" value="M"
    onclick="submit ()"M </td>
    </tr>
    <tr>
    <td><input type="radio" name="abbr_lett er" value="N"
    onclick="submit ()"N </td>
    <td><input type="radio" name="abbr_lett er" value="O"
    onclick="submit ()"O </td>
    <td><input type="radio" name="abbr_lett er" value="P"
    onclick="submit ()"P </td>
    <td><input type="radio" name="abbr_lett er" value="Q"
    onclick="submit ()"Q </td>
    <td><input type="radio" name="abbr_lett er" value="R"
    onclick="submit ()"R </td>
    <td><input type="radio" name="abbr_lett er" value="S"
    onclick="submit ()"S </td>
    <td><input type="radio" name="abbr_lett er" value="T"
    onclick="submit ()"T </td>
    <td><input type="radio" name="abbr_lett er" value="U"
    onclick="submit ()"U </td>
    <td><input type="radio" name="abbr_lett er" value="V"
    onclick="submit ()"V </td>
    <td><input type="radio" name="abbr_lett er" value="W"
    onclick="submit ()"W </td>
    <td><input type="radio" name="abbr_lett er" value="X"
    onclick="submit ()"X </td>
    <td><input type="radio" name="abbr_lett er" value="Y"
    onclick="submit ()"Y </td>
    <td><input type="radio" name="abbr_lett er" value="Z"
    onclick="submit ()"Z </td>
    </tr>
    </TABLE>

    <br>
    </FORM>
    <b><FORM NAME="author" method="POST" action="<?php echo
    $_SERVER['PHP_SELF'];?>"></b>
    <SELECT NAME="author_pk " SIZE="20" COLS="10" onclick="submit ()">

    --
    Thanks in Advance... http://ichbin.9999mb.com
    IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
    _______________ _______________ _______________ _______________ __________
    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
  • BKDotCom

    #2
    Re: Calling Javascript function in php script.

    echo the function call from php likey so?
    echo 'setCheckedValu e("abbr_letter" , "'.$_SESSIO N['abbr_letter'].'");
    '; //?

    Comment

    • IchBin

      #3
      Re: Calling Javascript function in php script.

      BKDotCom wrote:
      echo the function call from php likey so?
      echo 'setCheckedValu e("abbr_letter" , "'.$_SESSIO N['abbr_letter'].'");
      '; //?
      >
      Thanks for the call format. I think I maybe having a problem with the
      javascript function.

      --
      Thanks in Advance... http://ichbin.9999mb.com
      IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
      _______________ _______________ _______________ _______________ __________
      'If there is one, Knowledge is the "Fountain of Youth"'
      -William E. Taylor, Regular Guy (1952-)

      Comment

      • IchBin

        #4
        Re: Calling Javascript function in php script.

        IchBin wrote:
        BKDotCom wrote:
        >echo the function call from php likey so?
        >echo 'setCheckedValu e("abbr_letter" , "'.$_SESSIO N['abbr_letter'].'");
        >'; //?
        >>
        >
        Thanks for the call format. I think I maybe having a problem with the
        javascript function.
        >
        Yea, I rewrote the js function and I know it works now... I just need to
        find the right place to call it in my code.

        function setCheckedValue (newValue) {
        var len = document.author _abbrv.abbr_let ter.length
        for(var i = 0; i < len; i++) {
        document.author _abbrv.abbr_let ter[i].checked = false;
        if(document.aut hor_abbrv.abbr_ letter[i].value ==
        newValue.toStri ng()) {
        document.author _abbrv.abbr_let ter[i].checked = true;
        }
        }
        }

        --
        Thanks in Advance... http://ichbin.9999mb.com
        IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
        _______________ _______________ _______________ _______________ __________
        'If there is one, Knowledge is the "Fountain of Youth"'
        -William E. Taylor, Regular Guy (1952-)

        Comment

        • Jerry Stuckle

          #5
          Re: Calling Javascript function in php script.

          IchBin wrote:
          IchBin wrote:
          >
          >BKDotCom wrote:
          >>
          >>echo the function call from php likey so?
          >>echo 'setCheckedValu e("abbr_letter" , "'.$_SESSIO N['abbr_letter'].'");
          >>'; //?
          >>>
          >>
          >Thanks for the call format. I think I maybe having a problem with the
          >javascript function.
          >>
          Yea, I rewrote the js function and I know it works now... I just need to
          find the right place to call it in my code.
          >
          function setCheckedValue (newValue) {
          var len = document.author _abbrv.abbr_let ter.length
          for(var i = 0; i < len; i++) {
          document.author _abbrv.abbr_let ter[i].checked = false;
          if(document.aut hor_abbrv.abbr_ letter[i].value ==
          newValue.toStri ng()) {
          document.author _abbrv.abbr_let ter[i].checked = true;
          }
          }
          }
          >
          You can't "call" a JS function from your code. PHP runs on the server,
          and JS on the client.

          You can, however, echo a value from PHP in the JS code.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • IchBin

            #6
            Re: Calling Javascript function in php script.

            Jerry Stuckle wrote:
            IchBin wrote:
            >IchBin wrote:
            >>
            >>BKDotCom wrote:
            >>>
            >>>echo the function call from php likey so?
            >>>echo 'setCheckedValu e("abbr_letter" , "'.$_SESSIO N['abbr_letter'].'");
            >>>'; //?
            >>>>
            >>>
            >>Thanks for the call format. I think I maybe having a problem with the
            >>javascript function.
            >>>
            >Yea, I rewrote the js function and I know it works now... I just need
            >to find the right place to call it in my code.
            >function setCheckedValue (newValue) {
            > var len = document.author _abbrv.abbr_let ter.length
            > for(var i = 0; i < len; i++) {
            > document.author _abbrv.abbr_let ter[i].checked = false;
            > if(document.aut hor_abbrv.abbr_ letter[i].value ==
            >newValue.toStr ing()) {
            > document.author _abbrv.abbr_let ter[i].checked = true;
            > }
            > }
            >}
            >>
            >
            You can't "call" a JS function from your code. PHP runs on the server,
            and JS on the client.
            >
            You can, however, echo a value from PHP in the JS code.
            >
            Thanks...

            --
            Thanks in Advance... http://ichbin.9999mb.com
            IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
            _______________ _______________ _______________ _______________ __________
            'If there is one, Knowledge is the "Fountain of Youth"'
            -William E. Taylor, Regular Guy (1952-)

            Comment

            Working...