Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change javascript code to php

    Hi,

    I'v been asked to change my javascript to php code. Please can u tel me how to change the javascript below to php. I am using some php. It's basically onclick of items in a listbox, I populate certain fields....

    thanks


    <?
    echo "<TD rowspan=7 height=\"120\"><SELECT NAME=\"LstSchoolName\" ID=\"LstSchoolName\" SIZE=\"8\" ONCHANGE=\"Schoolselected(this);\" >
    \n";

    $sJavaScript = "function Schoolselected(elem)

    { for (var i = document.f1.length; i >= 0; i--)
    { document.f1.txtSchool.value[i] = null
    document.f1.txtAddr.value[i] = null

    $SName="";

    while ( $row = mysql_fetch_array($result) )
    {
    If ($SName!=$row["SchoolName"]){

    $SName = $row["SchoolName"];
    echo "\n<OPTION VALUE='".$row["SchoolName"]."'>".$SName."</OPTION>
    ";

    // and add a new section to the javascript...

    $sJavaScript = $sJavaScript."}\n"."if (elem.options[elem.selectedIndex].value=='".$row["SchoolName"]."'){\n";

    $sJavaScript = $sJavaScript."document.f1.txtSchool.value = ('".$row["SchoolName"]."');\n";
    $sJavaScript = $sJavaScript."document.f1.txtAddr.value = ('".$row["Street"]."');\n";

    $sJavaScript = $sJavaScript."if (document.f1.txtFundedBy.value == 'SCHOOL'){\n";
    $sJavaScript = $sJavaScript."document.f1.txtAddr1.value = ('".$row["Street"]."');\n";
    $sJavaScript = $sJavaScript."document.f1.txtName.value = ('".$row["SchoolName"]."')}\n";

    }
    }
    $sJavaScript = $sJavaScript."\n}\n}\n";
    echo "\n<SCRIPT LANGUAGE=\"JavaScript\">";
    echo "\n".$sJavaScript."\n</SCRIPT>\n";
    ?>

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey J-in-uk,

    The only way to have the PHP alter the value is to make the "onChange" equal submit() [onChange='submit()'] and then process the value using PHP and alter the other elements of the form.

    -Hawkmoon

    PS You would need to enclose the <SELECT> in <FORM>

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Do not create multiple topics with the same question. All replies need to go in the thread that raf has listed which is your original thread.

    Closing thread...
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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