Hi guys; I'm building a website for my A level ICT project; I need an area where the admin can add extra categories at will without having to manually dive in to the code.
I wanted to achieve this through a simple PHP post system that automatically generates a new category field when the admin enters the desired name in his/her CP
The script I currently have is as follows
// Defines that we are calling a function//
$(function(){
// 13 = the return key, when return is pressed inside the div "createcat" then trigger the function
$('#createcat').live("keypress",function(e){
if(e.which == 13)
{
//Variable, inputbox is echoed through following post script when
//the value is equal to what is contained in the box.
var inputbox = $(this).val();
//Execute script once Return is pressed on keyboard
//Send a XMLHttpRequest to process the rest of procedure.
if(window.XMLHttpRequest)
{
xmlhttp = new window.XMLHttpRequest //Variable
}
else
{
xmlhttp = new ActiveXObject ('Microsoft',XMLHTTP);
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == '4' && xmlhttp.status == '200')
{
}
}
//Defines the parameters in use, Variable line 10.
parameters = 'inputbox=' + inputbox;
//Posts the information to the PHP script, create-cat.php
xmlhttp.open('POST','scripts/create-cat.php',true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send(parameters);
}
});
});
This file in turn links too
<!--////////////////////////////////////////////////////////
// Project : Absolute Beginners log in system ///////////
// Purpose : A2 Level Coursework for ICT ////////////////
// Teacher : Mr L Hawkins ///////////////////////////////
// Student : Alex Sims //////////////////////////////////
// Candidate No. : 4173 /////////////////////////////////
// Centre No : 27168 ////////////////////////////////////
/////////////////////////////////////////////////////////-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"/></script>
<script type="text/javascript" src="javascript/create-cat.js"/></script>
<script type="text/javascript" src="javascript/custom.js"/></script>
<?php include_once('includes/header.php') ; ?>
<script type="text/javascript" >
$(document).ready(function() {
$("#markItUp").markItUp(mySettings);
});
</script>
<div id="subheader">
<div class="col-full">
<ul id="submenu">
</ul>
</ul>
</ul>
</div> <!-- end subheader -->
<!-- Start Main Div section -->
<div class="col-full">
<div id="leftsection">
<h2>Create Posts</h2>
<div class="form-elements">
<input type"text" name"title" placeholder="Add Title Here" id="title"/>
</div><!-- End of Left Section -->
<div class="form-elements">
<textarea id="markItUp" name"content"></textarea>
</div> <!-- Installed Text Editor -->
<div class="form-elements">
<input type"text" name"metatitle" placeholder="Meta Title" id="metatitle"/>
</div>
<div class="form-elements">
<input type"text" name"metadescription" placeholder="Meta Description" id="metadescription"/>
</div>
<div class="form-elements">
<input type"text" name"metarobots" placeholder="Meta Robots" id="metarobots"/>
</div>
<div class="form-elements">
<input type"text" name"metatags" placeholder="Meta Tags" id="metatags"/>
</div>
<div id="rightsection">
<h2>Categories</h2>
<div id="listcategores">
<div class="form-elements2">
<input type="checkbox" name="categoryname" value="" id="categoryname"/> Category 1
</div>
<div class="form-elements2">
<input type="checkbox" name="categoryname" value="" id="categoryname"/> Category 2
</div> <!-- end category list -->
<div id="createcat">
<div class="form-elements">
<input type="text" name"categorycreate" id"categorycreate" placeholder="Add New Category"/>
</div><!-- end createcat-->
<div class="clear"></div>
</div><!--end mainWrapper-->
</body>
</html>
Now I know that it works to some degree, as when I press enter whilst displaying it firebug tells me the script posts to where I want it to; great, but in there field no data is conveyed.
I've tried playing with different variables and scouring through pages of JS threads online and my syntax doesn't appear wrong from what I can see.
If anyone has any sort of idea would be greatly appreciated!
Thanks
Alex.