...

View Full Version : code to duplicate fields



Sycren
03-11-2009, 03:35 PM
Hi, im trying to get this code to duplicate the fields when having clicked the link (add another Question), but the link is not showing.. :s and its not working..



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Quiz Generator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="forms.css" />

<script type="text/javascript">
$(document).ready(function() {
$('#da').append('<p><a href="add" id="add_da">add another Question</a></p>');
$('#add_da').click(function() {
this.i++
$('#da1').parent().append("<div><hr />" + $('#da1').html().replace(/value="[^"]+"/g, 'value=""').replace(/_1/g, '_' + this.i) + '<a href="remove" class="remove_da">remove this question</a></div>');
$('.remove_da').click(function() { $(this).parent().remove(); return false; });
return false;
})[0].i = 1;
});
</script>
</head>


<body id="thedocument">
<h1>Quiz Generator</h1>
<div class="opener section">
<p>Generates Quiz code for GeoHop</p>
</div>

<div class="section">
<h2>Boo</h2>
<fieldset title="Introduction">
<legend>Generator</legend>
<p>
<form action="" method="get">
<div class="intro" id="da">
<p>Please enter the Question</p>
</div>
<div id="da1">
<p>
<label for="question_1">Question</label>
<input name="question_1" id="question_1" type="text" tabindex="1" />
</p>
<p>
<label for="answer1_1">Answer 1</label>
<input name="answer1_1" id="answer1_1" type="text" tabindex="2" />
</p>
<p>
<label for="answer2_1">Answer 2</label>
<input name="answer2_1" id="answer2_1" type="text" tabindex="2" />
</p>
<p>
<label for="answer3_1">Answer 3</label>
<input name="answer3_1" id="answer3_1" type="text" tabindex="2" />
</p>
<p>
<label for="answer3_1">Answer 4</label>
<input name="answer3_1" id="answer3_1" type="text" tabindex="2" />
</p>
</hr>
<p>
Answer 1: <input type="radio" name="correctAnswer" />
Answer 2: <input type="radio" name="correctAnswer" />
Answer 3: <input type="radio" name="correctAnswer" />
Answer 4: <input type="radio" name="correctAnswer" />
</p>
</div>
</fieldset>
</div>
</form>
</p>
<p>

</p>
</fieldset>
</div>
<div class="section">

<fieldset>
<legend></legend>

</fieldset>

</div>

</body>
</html>

I realise that there is no submit for the form or any action, this is intentional at the moment..

Thanx for any help

Eldarrion
03-11-2009, 03:43 PM
The code looks like it's jQuery, but I don't see a link to jQuery.js in your code? Are you sure you've included it? Firebug's complaint was... "$ is undefined" which in turn means... no jQuery is included. I did add jQuery myself to it and it seemed to work fine from then on (Haven't tested if the link does what it's supposed to do, but it should.)



<script type="text/javascript" src="path to jquery"></script>


Try this, see how it works.

Sycren
03-11-2009, 03:47 PM
Thankyou very much, dont know how i missed that :s

On regards to linking to jquery, its often better to use googles hosted version. See more here: http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/

Eldarrion
03-11-2009, 03:56 PM
On regards to linking to jquery, its often better to use googles hosted version. See more here: http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/


Eh, my personal point of view is that it should be kept on the server, that way when a new release comes out with a bug(which can happen with anything, really), you know your website won't act strangely, plus if for some reason google's hosting does decide to go AWOL, you know your site is still up and running as intended, barring any breakdowns from the server's ISP.

Sycren
03-11-2009, 06:40 PM
Im trying to write a javascript script that takes the entries of the form and exports it as xml, Could you offer any insight?

My first idea was to include a variable n for how many questions have been asked, and to read all the entries into an array of size n.. and to produce the xml that way..

Im quite new to javascript and know more java so I guess theres an easier way using the standard libraries or jquery?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum