View Full Version : change javascript code to php

03-25-2004, 06:36 PM

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


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

$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


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";

04-01-2004, 04:55 AM
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.


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

04-01-2004, 08:34 AM

04-01-2004, 09:20 AM
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...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum