如何让javascript填充textareas

时间:2016-03-02 09:22:09

标签: javascript php

希望有人能够帮助解决这个问题。我有一个表单,当您从下拉菜单中选择一个页面时,它应该使用数据库中的内容填充字段。这是有效的,但由于一些奇怪的原因,只是停了一夜。也许这是我做过的事情,没有意识到。源代码显示JavaScript从数据库获取所有内容并存储在数组中。但它没有根据PageId中的选择填充文本字段。

update_page.php

<?php /*
if(!isset($_SESSION['user']))
{
 header("Location: login.php");
}  */
//$vbCrLf = chr(13).chr(10);
    $vbCrLf = "";

    require ('dbconnect.php');


    //create and execute query
    $query = 'SELECT PageId, PageTitle, PageContent, PageContent2 FROM pages ORDER BY PageId';
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());

    //create selection list
    $DropDownList = "<select name='PageId' id='PageId' onchange='SelectChanged();'> ".$vbCrLf;
    //$DropDownList .= "<option value=''>--SELECT PAGE--</option> ".$vbCrLf;
    // this is unnecessary it will just give an error

    while($row = mysql_fetch_row($result))
    {
        $heading = htmlentities($row[0]);
        // dont need these so delete them
        //echo "<p>\$heading=$heading</p>";
        //echo "<p>\$row[1]=$row[1]</p>";
        $DropDownList .= "<option value='$heading'>".htmlentities($row[1])."</option> ".$vbCrLf;
        $PageTitlePhp .= 'PageTitleArray['.$heading.']="'.htmlentities($row[1]).'";'.$vbCrLf;
        $PageContentPhp .= 'PageContentArray['.$heading.']="'.htmlentities($row[2]).'";'.$vbCrLf;
        $PageContent2Php .= 'PageContent2Array['.$heading.']="'.htmlentities($row[3]).'";'.$vbCrLf;
    }

    $DropDownList .= "</select> ".$vbCrLf;
?>

<html>
<head>
<title>Update Page</title>
</head>

<body>


<!-- Pages avaliable below -->
<?php /*
//Show which pages are active in the database, and therefore can be updated
require('mysqli.php');

$sql = "SELECT PageId, PageTitle FROM pages ORDER BY PageId";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // Create a table to display the PageId and PageTitle
        echo '<table border="1" style="width:30%">
                <tr>
                    <td><b>Page ID</b></td>
                    <td><b>Page Title</b></td>
                </tr>';

        // Show the pages in the table
        while($row = $result->fetch_assoc()) {
            echo "
                <tr>
                    <td>{$row['PageId']}</td>
                    <td>{$row['PageTitle']}</td>                  
                </tr>";
        }

        // Close table
        echo '</table>';
} else {
    echo "0 results";
}
$conn->close();
*/?>
<!-- Pages avaliable above -->

<br>
<!-- php below; Creates a form to update database content -->
<form  method="post"  action="update_website_page_handle.php">
<table width="943" height="528">
  <tr>
    <td align="right">&nbsp;</td>
    <td height="32" colspan="2" align="left"><h1> Update Page </h1></td>
    </tr>
  <tr>
    <td width="60" align="left">&nbsp;</td>
    <td width="134" height="32" align="left"><p>Select Page ID:</p></td>
    <td width="733">
        <?php echo $DropDownList; ?>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Page Title:</p></td>
    <td><textarea style="width: 500px; height: 50px;" name="PageTitle" id="PageTitle" class="heading"></textarea></td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Page Content:</p></td>
    <td>
      <textarea style="width: 500px; height: 200px;" name="PageContent" id="PageContent" class="date"></textarea>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Extra Page Content:</p></td>
    <td>
      <textarea style="width: 500px; height: 200px;" name="PageContent2" id="PageContent2" class="details"></textarea>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>
      <input name="update" type="submit"  id="update" value="Update">
    </td>
  </tr>
</table>
</form>
<script language="Javascript" type="text/javascript">
    var PageTitleArray = new Array();
    <?php echo $PageTitlePhp; ?>
    var PageContentArray = new Array();
    <?php echo $PageContentPhp; ?>
    var PageContent2Array = new Array();
    <?php echo $PageContent2Php; ?>
    function SelectChanged()
    {
        var PageId = document.getElementById('PageId').value;
        document.getElementById('PageTitle').value = PageTitleArray[PageId];
        document.getElementById('PageContent').value = PageContentArray[PageId];
        document.getElementById('PageContent2').value = PageContent2Array[PageId];
    }
    SelectChanged(); // added to execute the function after loading to select first value.
</script>
</body>
</html>

因此,从下拉列表中选择PageId时,它不会填充表单中的字段,而且应该填充。

下图显示了表单:update_page.php 在此先感谢您的帮助。

消息来源

<html>
<head>
<title>Update Page</title>
</head>

<body>


<!-- Pages avaliable below -->
<!-- Pages avaliable above -->

<br>
<!-- php below; Creates a form to update database content -->
<form  method="post"  action="update_website_page_handle.php">
<table width="943" height="528">
  <tr>
    <td align="right">&nbsp;</td>
    <td height="32" colspan="2" align="left"><h1> Update Page </h1></td>
    </tr>
  <tr>
    <td width="60" align="left">&nbsp;</td>
    <td width="134" height="32" align="left"><p>Select Page ID:</p></td>
    <td width="733">
        <select name='PageId' id='PageId' onchange='SelectChanged();'> <option value='1'>About Us</option> <option value='2'>News</option> <option value='3'>Nursery</option> <option value='4'>Information</option> <option value='5'>Vision & Ethos</option> <option value='6'>Classes</option> <option value='7'>Dragonflies</option> <option value='8'>Hedgehogs</option> <option value='9'>Welcome to Easebourne Primary School!</option> <option value='10'>January 2016</option> <option value='11'>Februrary 2016</option> <option value='13'>About Us</option> <option value='14'>Login</option> <option value='15'>Squirrels</option> <option value='16'>Rabbits</option> <option value='17'>Badgers</option> <option value='18'>Foxes</option> <option value='19'>Otters</option> <option value='20'>TESLA</option> <option value='21'>Staff</option> <option value='22'>Governors</option> <option value='23'>Curriculum</option> <option value='24'>Reading Schemes</option> <option value='25'>Topic Overview (2015-2017)</option> <option value='26'>Hedgehogs (Y1) Spring 2016: Houses & Homes</option> <option value='27'>Squirrels (Y2) Spring 2016: Houses & Homes</option> <option value='28'>Rabbits (Y3) Spring 2016: Storms & Shipwrecks</option> <option value='29'>Badgers (Y4) Spring 2016: Storms & Shipwrecks</option> <option value='30'>Otters (Y6) Spring 2016: The Revolting Romans</option> <option value='31'>Key Information</option> <option value='32'>Parent Information</option> <option value='33'>Policies</option> <option value='34'>Prospectus</option> <option value='35'>Local Offer</option> <option value='36'>September 2015</option> <option value='37'>October 2015</option> <option value='38'>November 2015</option> <option value='39'>December 2015</option> <option value='40'>Values and Ethos</option> <option value='41'>Ofsted & Diocesan Inspection Reports & Parent View</option> <option value='42'>Exam and Assessment Results</option> <option value='43'>Behaviour Policies</option> <option value='44'>Pupil Premium</option> <option value='45'>PE and Sport Premium</option> <option value='46'>Special Educational Needs and Disabilities</option> <option value='47'>Admission Arrangements</option> <option value='48'>School Lettings</option> <option value='49'>Charging and Remissions Policies</option> <option value='50'>School Diary</option> <option value='51'>Term Dates</option> <option value='52'>School Day</option> <option value='53'>Clubs</option> <option value='54'>Forest Schools</option> <option value='55'>Pupil Weblinks</option> <option value='56'>Medicines</option> <option value='57'>Attendance</option> <option value='58'>Child Protection Policy (Nov 2015)</option> <option value='59'>Behaviour and Anti-Bullying Policy (Nov 2015)</option> <option value='60'>Accessibility Plan (Nov 2015)</option> <option value='61'>Local & SEND Offer, including Inclusion & SEND Policy (Sep 2</option> <option value='62'>Safeguarding Statement</option> <option value='63'>Data Protection Policy (Nov 2015)</option> <option value='64'>SRE (Sex & Relationships Education) Policy (Jun 2015)</option> <option value='65'>Marking, Review & Feedback Policy (Nov 2015)</option> <option value='66'>Health & Safety Policy (Dec 2015)</option> </select>     </td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Page Title:</p></td>
    <td><textarea style="width: 500px; height: 50px;" name="PageTitle" id="PageTitle" class="heading"></textarea></td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Page Content:</p></td>
    <td>
      <textarea style="width: 500px; height: 200px;" name="PageContent" id="PageContent" class="date"></textarea>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Extra Page Content:</p></td>
    <td>
      <textarea style="width: 500px; height: 200px;" name="PageContent2" id="PageContent2" class="details"></textarea>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>
      <input name="update" type="submit"  id="update" value="Update">
    </td>
  </tr>
</table>
</form>
<script language="Javascript" type="text/javascript">
    var PageTitleArray = new Array();
    PageTitleArray["1"]="About Us";PageTitleArray["2"]="News";PageTitleArray["3"]="Nursery";PageTitleArray["4"]="Information";PageTitleArray["5"]="Vision & Ethos";PageTitleArray["6"]="Classes";PageTitleArray["7"]="Dragonflies";PageTitleArray["8"]="Hedgehogs";PageTitleArray["9"]="Welcome to Easebourne Primary School!";PageTitleArray["10"]="January 2016";PageTitleArray["11"]="Februrary 2016";PageTitleArray["13"]="About Us";PageTitleArray["14"]="Login";PageTitleArray["15"]="Squirrels";PageTitleArray["16"]="Rabbits";PageTitleArray["17"]="Badgers";PageTitleArray["18"]="Foxes";PageTitleArray["19"]="Otters";PageTitleArray["20"]="TESLA";PageTitleArray["21"]="Staff";PageTitleArray["22"]="Governors";PageTitleArray["23"]="Curriculum";PageTitleArray["24"]="Reading Schemes";PageTitleArray["25"]="Topic Overview (2015-2017)";PageTitleArray["26"]="Hedgehogs (Y1) Spring 2016: Houses & Homes";PageTitleArray["27"]="Squirrels (Y2) Spring 2016: Houses & Homes";PageTitleArray["28"]="Rabbits (Y3) Spring 2016: Storms & Shipwrecks";PageTitleArray["29"]="Badgers (Y4) Spring 2016: Storms & Shipwrecks";PageTitleArray["30"]="Otters (Y6) Spring 2016: The Revolting Romans";PageTitleArray["31"]="Key Information";PageTitleArray["32"]="Parent Information";PageTitleArray["33"]="Policies";PageTitleArray["34"]="Prospectus";PageTitleArray["35"]="Local Offer";PageTitleArray["36"]="September 2015";PageTitleArray["37"]="October 2015";PageTitleArray["38"]="November 2015";PageTitleArray["39"]="December 2015";PageTitleArray["40"]="Values and Ethos";PageTitleArray["41"]="Ofsted & Diocesan Inspection Reports & Parent View";PageTitleArray["42"]="Exam and Assessment Results";PageTitleArray["43"]="Behaviour Policies";PageTitleArray["44"]="Pupil Premium";PageTitleArray["45"]="PE and Sport Premium";PageTitleArray["46"]="Special Educational Needs and Disabilities";PageTitleArray["47"]="Admission Arrangements";PageTitleArray["48"]="School Lettings";PageTitleArray["49"]="Charging and Remissions Policies";PageTitleArray["50"]="School Diary";PageTitleArray["51"]="Term Dates";PageTitleArray["52"]="School Day";PageTitleArray["53"]="Clubs";PageTitleArray["54"]="Forest Schools";PageTitleArray["55"]="Pupil Weblinks";PageTitleArray["56"]="Medicines";PageTitleArray["57"]="Attendance";PageTitleArray["58"]="Child Protection Policy (Nov 2015)";PageTitleArray["59"]="Behaviour and Anti-Bullying Policy (Nov 2015)";PageTitleArray["60"]="Accessibility Plan (Nov 2015)";PageTitleArray["61"]="Local & SEND Offer, including Inclusion & SEND Policy (Sep 2";PageTitleArray["62"]="Safeguarding Statement";PageTitleArray["63"]="Data Protection Policy (Nov 2015)";PageTitleArray["64"]="SRE (Sex & Relationships Education) Policy (Jun 2015)";PageTitleArray["65"]="Marking, Review & Feedback Policy (Nov 2015)";PageTitleArray["66"]="Health & Safety Policy (Dec 2015)";    var PageContentArray = new Array();
    PageContentArray["1"]="";PageContentArray["2"]="";PageContentArray["3"]="";PageContentArray["4"]="";PageContentArray["5"]="Our Vision & Ethos Documentation";PageContentArray["6"]="";PageContentArray["7"]="Dragonflies (Reception Class) is situated at the heart of our Early Years Foundation Stage Unit. Our Teacher is called Mrs Catchpole and our teaching assistants are Mrs Mayhew and Mr Fleischner.";PageContentArray["8"]="Welcome to Hedgehogs Class. Our teacher is Miss Sykes and our teaching assistant is Mr Williams.";PageContentArray["9"]="Easebourne CE Primary School caters for children from 4 to 11 years and occupies a newly refurbished site in Easebourne village, at the heart of the South Downs National Park. Our Early Days Nursery provides facilities for children from 6 months to 4 years, as well as before- and after-school care and a holiday club.";PageContentArray["10"]="January News";PageContentArray["11"]="February News";PageContentArray["13"]="Our purpose built nursery offers full day care children from 6 months to 4 years. We have three beautifully designed rooms:-

Caterpillars - Babies (6 months - 2 years)

Ladybirds - Toddlers (2 years - 3 years)

Bumblebees - Pre-school (3 years - 4 years)";PageContentArray["14"]="login";PageContentArray["15"]="Welcome to Squirrels' class page. Our teacher is Miss Evans and our teaching assistants are Mrs Wakeford and Mrs Hill.";PageContentArray["16"]="Welcome to Rabbits' class page. Our teacher is Miss Crew and our teaching assistant is Mrs Cella.";PageContentArray["17"]="Welcome to Badgers' class page. Our teacher is Mr Taylor and our teaching assistant is Mrs Pilcher.";PageContentArray["18"]="Welcome to Foxes Class. Our teacher is Mrs Rashleigh and our teaching assistant is Mrs Cobbold.";PageContentArray["19"]="Welcome to Otters' class page. Our teachers are Mr Meaby and Mrs Wade-Palmer. Our teaching assistants are Mrs Ashcroft and Mrs Thomas.";PageContentArray["20"]="We are a member of the TESLA Teaching School Alliance.  TESLA is a partnership of educators who have the highest expectations and are striving to achieve exceptional education for all by removing barriers to learning, challenging established pedagogy and raising aspirations.";PageContentArray["21"]="Mr Culley
Head Teacher
Mrs Catchpole
Dragonflies (YR) Class Teacher
Miss Evans
Squirrels (Yr 2) Classteacher
Mr Taylor
Badgers (Yr 4) Class Teacher
Mrs Stevens
Dragonflies (YR) Teacher and Music Teacher
Mrs Rogers
French Teacher
Mrs Ashcroft
Teaching Assistant
Mrs Pilcher
Teaching Assistant
Mrs Wakeford
Teaching Assistant
Mrs Hill
Teaching Assistant
Mrs Bennington
School Secretary
Mrs Pimm
School Business Manager
Mrs Burnell-Budd
Midday Meals Supervisor
Miss Beadle
Nursery Supervisor
Mrs Budd
Nursery Assistant
Mrs Turner
Nursery Assistant
Mr Meaby
Deputy Head & Otters (Yr 6) Class Teacher
Miss Sykes
Hedgehogs (Yr 1) Class Teacher
Miss Crew
Rabbits (Yr 3) Class Teacher
Mrs Rashleigh
Foxes (Yr 5) Class Teacher
Mrs Wade-Palmer
Otters (Yr 6) Teacher
Mrs Austin-Diment
SENCO
Mrs Cobbold
Teaching Assistant
Mrs Cella
Teaching Assistant
Mr Williams
Teaching Assistant
Mrs Waugh
School Secretary
Mr Stonard
Premises Officer
Mrs Quartermaine-Gates
Midday Meals Supervisor
Mrs Hill
Nursery Assistant
Miss Ford
Nursery Assistant
Miss Kennedy
Nursery Assistant";PageContentArray["22"]="School Governors are the largest voluntary group in the UK!
Governors represent all stakeholders in the school and together help decide on the direction, focus and ethos of the school. Representatives from the school staff, parents, local community and church means that school decisions are made by people with a wide range of experiences and views.";PageContentArray["23"]="";PageContentArray["24"]="The School currently uses Letters & Sounds and Jolly Phonics for the teaching of phonics.  The key reading schemes used in Key Stage 1 are PM and Oxford Reading Tree Scheme. ";PageContentArray["25"]="Documentation for Topic Overview";PageContentArray["26"]="Documentation";PageContentArray["27"]="Documentation";PageContentArray["28"]="Documenation";PageContentArray["29"]="Documenation";PageContentArray["30"]="Documenation";PageContentArray["31"]="";PageContentArray["32"]="";PageContentArray["33"]="";PageContentArray["34"]="Prospectus Documentation";PageContentArray["35"]="Local OFfer";PageContentArray["36"]="September News";PageContentArray["37"]="October News";PageContentArray["38"]="November News";PageContentArray["39"]="December News";PageContentArray["40"]="The spirit of Easebourne C.E. Primary School reflects the commitment of staff and governors to its Christian foundation; to loyalty, integrity, justice, equality, respect, courtesy and enthusiasm; and to the expectation of the highest standards from all members of the school community in all aspects of school life and beyond.  The Headteacher, staff and governors are committed to working in partnership and to the expectation of strong leadership.  They believe that they, together with pupils and parents, should be proud to belong to Easebourne School.

 We aspire for all our children to be happy and become confident, secure, caring individuals who achieve personal success and develop a love of learning.";PageContentArray["41"]="Ofsted Documentation";PageContentArray["42"]="The DfE website has information about the school, including the 2015 KS2 performance tables:

http://www.education.gov.uk/cgi-bin/schools/performance/school.pl?urn=126003

The Ofsted Data Dashboard has information about the previous year's assessments for KS1 and KS2:

http://dashboard.ofsted.gov.uk/dash.php?urn=126003

You can find a brief summary of our KS2 data from 2015 below:";PageContentArray["43"]="Behaviour Documentation";PageContentArray["44"]="Pupil Premium Documentation";PageContentArray["45"]="PE and Sport Premium Documentation";PageContentArray["46"]="Special Educational Needs and Disabilities Documentation";PageContentArray["47"]="Please contact the school office on 01730 813266 if you are interested in applying for a place at Easebourne C.E. Primary School. We welcome visits to the school from prospective parents and pupils.
The link below provides information on the school admissions process at West Sussex County Council.";PageContentArray["48"]="School Lettings Documentation";PageContentArray["49"]="Charging and Remissions Policies Documentation
";PageContentArray["50"]="School Diary Documentation";PageContentArray["51"]="The link below will take you to the relevant West Sussex County Council website.

Click here for the school term dates for this year and next year.";PageContentArray["52"]="Classes, Registrations & Breaks

Children can enter classes from 8.40

Morning Registration 8.40-8.50

Morning Classes 8.50 - 12.00 (KS1)

Morning Classes 8.50 - 12.10 (KS2)

Morning Break 10.30 - 10.45

Afternoon Classes 1.05 - 3 .15

Afternoon Registration 1.05-1.10

Afternoon Break 2.00 - 2.15 (KS1) except Tuesday

 

Assemblies

Monday Whole School - Hall 2.50 - 3.05

Tuesday Whole School - Hall 2.50 - 3.05

Wednesday Whole School - Hall 2.50 - 3.05

Thursday Whole School - Hall 10.10-10.30

Friday Whole School - Hall 2.50 - 3.05";PageContentArray["53"]="Clubs Documentation";PageContentArray["54"]="Forest Schools Documentation
";PageContentArray["55"]="The links below take you to Moodle, the school's VLE (Virtual Learning Environment) and the external educational maths resource, Sumdog.  The passwords for these programmes can be found within KIT Books or obtained from class teachers or office administrators.
 
Click here for Moodle.
 
Click here for Sumdog.
 
Also included here is the AR Bookfind weblink.  This helps older children find books which are on their current reading level, fit with their interests and are on the Accelerated Reader scheme.
 
Click here for AR Bookfind.";PageContentArray["56"]="Medicines Documentation";PageContentArray["57"]="Parents and Carers are legally responsible for ensuring school age children receive a suitable full time education. With only 190 days in the school year, there are 175 days left for holidays, treats and shopping. Taking holidays and other unnecessary absences in term time means your son/daughter will be missing vital elements of their education.

Please note that only a Headteacher can authorise any absence, not the parent or carer. Government Regulations which took effect from 1st September 2013 state that Headteachers may not grant any leave of absence during term time unless there are exceptional circumstances. Any exceptional circumstances will be discussed case by case but we will need proof that it is not just holiday.";PageContentArray["58"]="Child Protection Policy (Nov 2015) documentation";PageContentArray["59"]="Behaviour and Anti-Bullying Policy (Nov 2015) Documentation
";PageContentArray["60"]="Accessibility Plan (Nov 2015) Documentation
";PageContentArray["61"]="Local & SEND Offer, including Inclusion & SEND Policy (Sep 2015)
documentation";PageContentArray["62"]="Safeguarding Statement Documentation
";PageContentArray["63"]="Data Protection Policy (Nov 2015) documentation
";PageContentArray["64"]="SRE (Sex & Relationships Education) Policy (Jun 2015) Documentation
";PageContentArray["65"]="Marking, Review & Feedback Policy (Nov 2015) documentation
";PageContentArray["66"]="Health & Safety Policy (Dec 2015)Documenation
";    var PageContent2Array = new Array();
    PageContent2Array["1"]="";PageContent2Array["2"]="";PageContent2Array["3"]="";PageContent2Array["4"]="";PageContent2Array["5"]="";PageContent2Array["6"]="";PageContent2Array["7"]="";PageContent2Array["8"]="";PageContent2Array["9"]="The ethos of Easebourne C.E. Primary School reflects the commitment of staff, governors, parents and pupils to its Christian foundation. Visitors are warmly welcomed; please call or email us to arrange a time.";PageContent2Array["10"]="";PageContent2Array["11"]="";PageContent2Array["13"]="We welcome visits from prospective parents. To arrange a visit please call us on 01730 815046 or email us at ect@easebourne.w-sussex.sch.uk";PageContent2Array["14"]="";PageContent2Array["15"]="";PageContent2Array["16"]="";PageContent2Array["17"]="";PageContent2Array["18"]="";PageContent2Array["19"]="";PageContent2Array["20"]="";PageContent2Array["21"]="";PageContent2Array["22"]="The different types of Governors on our Governing Body
Co-opted Governors (3) - individuals chosen by the Governors from the local community who represent community interests
Foundation Governors (2) - individuals appointed by the church to help preserve and develop the school's religous character
Headteacher Governor (1)
Local Authority Governors (1) - individuals appointed by the LA who consider the skills and experience which schools require and appoint candidates who support the school's ethos and mission
Parent Governors (3) - parents or carers elected by other parents or carers with children at the school or, on occasion, appointed by the Governing Body
Staff Governors (1) - staff members elected by teaching and non-teaching staff";PageContent2Array["23"]="";PageContent2Array["24"]="";PageContent2Array["25"]="";PageContent2Array["26"]="";PageContent2Array["27"]="";PageContent2Array["28"]="";PageContent2Array["29"]="";PageContent2Array["30"]="";PageContent2Array["31"]="";PageContent2Array["32"]="";PageContent2Array["33"]="";PageContent2Array["34"]="";PageContent2Array["35"]="";PageContent2Array["36"]="";PageContent2Array["37"]="";PageContent2Array["38"]="";PageContent2Array["39"]="";PageContent2Array["40"]="By:-

being an inclusive school where all learners are given both equality and fair treatment
striving towards the highest standards for all
treating learners as individuals and differentiating teaching and learning to take account of their individual needs
creating a warm, welcoming, happy, safe and secure environment for all children
encouraging, valuing and extending every child’s contribution to the school
recognising and celebrating success in everyone
providing an exciting , broad and balanced curriculum; relevant to all children
building strong collaborative partnerships with families and the local community
encouraging and enabling the continuous professional development of all staff
Enabling our children to:-

develop lively enquiring minds, the ability to question, discuss and argue rationally and to apply themselves to tasks and physical skills
acquire knowledge and skills relevant to them now and in the future as adults, for life and employment in a rapidly changing world
use language and number effectively
develop personal and moral values, to encourage respect for religious values and understanding of other races religions and ways of life
develop appreciation of artistic achievements and to heighten their aesthetic awareness and creativity
understand the world in which they live and their place in it";PageContent2Array["41"]="";PageContent2Array["42"]="";PageContent2Array["43"]="";PageContent2Array["44"]="";PageContent2Array["45"]="";PageContent2Array["46"]="";PageContent2Array["47"]="If you have any further questions please do not hesitate to contact:-

Pupil Admissions Office
Centenary House
Durrington Lane
Worthing
West Sussex
BN13 2QB

Phone: 03330142903
Fax: 01903 839214
Email: admissions.south@westsussex.gov.uk";PageContent2Array["48"]="";PageContent2Array["49"]="";PageContent2Array["50"]="";PageContent2Array["51"]="In addition, schools have five Inset days for staff training each year.  Below are the school's dates for this academic year:

23rd October 2015
4th January 2016
24th March 2016
27th May 2016
13th June 2016";PageContent2Array["52"]="Summary

Total time in school 32 hours 05 minutes weekly

KS1 Total teaching time 23 hours 05 minutes weekly

KS2 Total teaching time 24 hours 55 minutes weekly";PageContent2Array["53"]="";PageContent2Array["54"]="";PageContent2Array["55"]="";PageContent2Array["56"]="";PageContent2Array["57"]="When a pattern of absence begins to cause concern, you will be contacted by a member of staff who will seek to work with you to resolve poor attendance. If a child is absent due to illness or a medical appointment parents should notify the school by close of register. A message can be left on the school’s absence line – Tel. No. 01730 813266. This should be followed up with an email or letter. If no contact is made or explanation provided the absence will be deemed unauthorised.";PageContent2Array["58"]="";PageContent2Array["59"]="";PageContent2Array["60"]="";PageContent2Array["61"]="";PageContent2Array["62"]="";PageContent2Array["63"]="";PageContent2Array["64"]="";PageContent2Array["65"]="";PageContent2Array["66"]="";    function SelectChanged()
    {
        var PageId = document.getElementById('PageId').value;
        document.getElementById('PageTitle').value = PageTitleArray[PageId];
        document.getElementById('PageContent').value = PageContentArray[PageId];
        document.getElementById('PageContent2').value = PageContent2Array[PageId];
    }
    SelectChanged(); // added to execute the function after loading to select first value.
</script>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

而不是,

DataSource

使用,

DataField

答案 1 :(得分:0)

您要做的是在textarea中提供文本。要做到这一点,你需要替换textarea代码:

<textarea
 style="width:500px;height:200px;"
 name="PageContent"
 id="PageContent"
 class="date"
 value="<?php echo $row['PageContent']; ?>">
</textarea>

有了这个:

<textarea
 style="width:500px;height:200px;"
 name="PageContent"
 id="PageContent"
 class="date">
  <?=htmlentities($PageContent)?>
</textarea>

您还可以看到代码已由http://stackoverflow.com的代码颜色系统更正。

htmlentities代码会对文本进行转义,因此如果内部有另一个</textarea>,则不会破坏代码。

此外,使用echo("");命令的一种简短方法是使用以下标记:<?=$variable?>或函数:<?=customFunction("hello")?>

编辑,1

    setTimeout(SelectChanged(),400); // run this to set the first values in the select element

这将自动选择<select>元素中的第一个值。使用此代码,您真的不需要PHP代码来尝试设置值。

答案 2 :(得分:0)

OK so what you were trying to do is set the values, then load them. But you didn't know that the script has to be after the code you want to edit. Because or else it will execute before the table is created.

<?php /*
if(!isset($_SESSION['user']))
{
 header("Location: login.php");
}  */
//$vbCrLf = chr(13).chr(10);
    $vbCrLf = "";

    require ('dbconnect.php');


    //create and execute query
    $query = 'SELECT PageId, PageTitle, PageContent, PageContent2 FROM pages ORDER BY PageId';
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());

    //create selection list
    $DropDownList = "<select name='PageId' id='PageId' onchange='SelectChanged();'> ".$vbCrLf;
    //$DropDownList .= "<option value=''>--SELECT PAGE--</option> ".$vbCrLf;
    // this is unnecessary it will just give an error

    while($row = mysql_fetch_row($result))
    {
        $heading = htmlentities($row[0]);
        // dont need these so delete them
        //echo "<p>\$heading=$heading</p>";
        //echo "<p>\$row[1]=$row[1]</p>";
        $DropDownList .= "<option value='$heading'>".json_encode($row[1])."</option> ".$vbCrLf;
        $PageTitlePhp .= 'PageTitleArray['.$heading.']='.json_encode($row[1]).';'.$vbCrLf;
        $PageContentPhp .= 'PageContentArray['.$heading.']='.json_encode($row[2]).';'.$vbCrLf;
        $PageContent2Php .= 'PageContent2Array['.$heading.']='.json_encode($row[3]).';'.$vbCrLf;
    }

    $DropDownList .= "</select> ".$vbCrLf;
?>

<html>
<head>
<title>Update Page</title>
</head>

<body>


<!-- Pages avaliable below -->
<?php /*
//Show which pages are active in the database, and therefore can be updated
require('mysqli.php');

$sql = "SELECT PageId, PageTitle FROM pages ORDER BY PageId";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // Create a table to display the PageId and PageTitle
        echo '<table border="1" style="width:30%">
                <tr>
                    <td><b>Page ID</b></td>
                    <td><b>Page Title</b></td>
                </tr>';

        // Show the pages in the table
        while($row = $result->fetch_assoc()) {
            echo "
                <tr>
                    <td>{$row['PageId']}</td>
                    <td>{$row['PageTitle']}</td>                  
                </tr>";
        }

        // Close table
        echo '</table>';
} else {
    echo "0 results";
}
$conn->close();
*/?>
<!-- Pages avaliable above -->

<br>
<!-- php below; Creates a form to update database content -->
<form  method="post"  action="update_website_page_handle.php">
<table width="943" height="528">
  <tr>
    <td align="right">&nbsp;</td>
    <td height="32" colspan="2" align="left"><h1> Update Page </h1></td>
    </tr>
  <tr>
    <td width="60" align="left">&nbsp;</td>
    <td width="134" height="32" align="left"><p>Select Page ID:</p></td>
    <td width="733">
        <?php echo $DropDownList; ?>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Page Title:</p></td>
    <td><textarea style="width: 500px; height: 50px;" name="PageTitle" id="PageTitle" class="heading"></textarea></td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Page Content:</p></td>
    <td>
      <textarea style="width: 500px; height: 200px;" name="PageContent" id="PageContent" class="date"></textarea>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td align="left" valign="top"><p>Extra Page Content:</p></td>
    <td>
      <textarea style="width: 500px; height: 200px;" name="PageContent2" id="PageContent2" class="details"></textarea>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>
      <input name="update" type="submit"  id="update" value="Update">
    </td>
  </tr>
</table>
</form>
<script language="Javascript" type="text/javascript">
    var PageTitleArray = new Array();
    <?php echo $PageTitlePhp; ?>
    var PageContentArray = new Array();
    <?php echo $PageContentPhp; ?>
    var PageContent2Array = new Array();
    <?php echo $PageContent2Php; ?>
    function SelectChanged()
    {
        var PageId = document.getElementById('PageId').value;
        document.getElementById('PageTitle').value = PageTitleArray[PageId];
        document.getElementById('PageContent').value = PageContentArray[PageId];
        document.getElementById('PageContent2').value = PageContent2Array[PageId];
    }
    SelectChanged(); // added to execute the function after loading to select first value.
</script>
</body>
</html>

Edit, 1

The value attributes were still there, i have removed them,

Edit, 2

I edited, to accommodate any special characters and escape them attempting not to cause issue with variable assignment.

-----Want to see it live?-----

Here is a live example of the code, but edited so it runs without the database and has preset values:

http://js.x10.bz/helpstack/35743000/update.php