I have this working in test6.php.But I use it in Codeigniter the new item displays and then reverts back to the original 3 questions. When I delete an answer it removes it and then reverts back to the original 3 questions.
test6.php
<!DOCTYPE html> <html> <head> <!–[removed][removed]–> [removed][removed]
[removed] $(document).ready(function(){ $(“#add”).click(function(){ var newNum= $(“#answerList li”).size() + 1; var text = ‘answer’ + newNum; //alert(text); var message =”<li>Answer<input type=’text’ id=”+text+” name=”+text+” ></li>”; $(“#answerList”).append(“<li>Answer<input type=’text’ id=”+text+” name=”+text+” ></li>”); //alert(message); });
$(“#delete”).click(function(){ $(“#answerList li:last”).remove(); }); }); [removed] </head>
<body> <ol id=”answerList”> <li>Answer<input type=”text” id=”answer1” name=”answer1” /></li> <li>Answer<input type=”text” id=”answer2” name=”answer2” /></li> <li>Answer<input type=”text” id=”answer3” name=”answer3” /></li> </ol> <button id=”add”>Add item</button> <button id=”delete”>Delete item</button> </body> </html>
admin/create
<?php echo validation_errors(); $this->load->helper(‘html’); ?>
<?php echo form_open(‘admin/create’) ?>
Title<input type=”text” id=”title” name=”title” /><br > Question<input type=”text” id=”question” name=”question” /><br >
<ol id="answerList">
<li><span class="answer">Answer</span><input type="text" id="answer1" name="answer1" /></li>
<li><span class="answer">Answer</span><input type="text" id="answer2" name="answer2" /></li>
<li><span class="answer">Answer</span><input type="text" id="answer3" name="answer3" /></li>
</ol>
<button type ="add" id="add">Add item</button>
<button type ="delete" id="delete">Delete item</button>
<input type="submit" name="submit" value="Create a question" />
</form>
master.php
<?php echo doctype(‘html5’);?>
<html>
<head>
<?php $this->load->helper(‘html’);
echo link_tag(‘css/poll.css’);?>
<!–gives <link href=”http://site.com/css/mystyles.css” rel=”stylesheet” type=”text/css” />–>
<title><?php echo $title; ?></title>
<meta http-equiv=”Content-Type” c charset=utf-8” />
<!–[removed][removed]
[removed][removed] –>
</head>
<body>
<div class=’container’>
<h1>New Zealand Polls</h1>
<div class = ‘navigation’>
<hr>
<?php $this->load->helper(‘url’); ?>
<?php /*?><?php echo anchor(‘http://localhost/CurrentWebsites/SENG365/polls/index.php/user.php’, ‘Home’);?> <?php */?>
<?php echo anchor(‘user’, ‘Home’);?>
<?php echo anchor(‘admin/create’, ‘Create’);?>
<?php echo anchor(‘pages/view/about’, ‘About’);?>
<hr>
</div>
<?php echo $content; ?>
<hr>
© 2013
</div>
[removed][removed]
[removed][removed]
</body>
</html>
poll.js
$(document).ready(function(){ $(“#add”).click(function(){ var newNum= $(“#answerList li”).size() + 1; var text = ‘answer’ + newNum; //alert(text); //var message =”<li>Answer<input type=’text’ id=”+text+” name=”+text+” ></li>”; $(“#answerList”).append(“<li>Answer<input type=’text’ id=”+text+” name=”+text+” ></li>”); //alert(message); });
$(“#delete”).click(function(){ $(“#answerList li:last”).remove(); });
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.