Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code to duplicate fields

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

    Code:
    <!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

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    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.)

    Code:
    <script type="text/javascript" src="path to jquery"></script>
    Try this, see how it works.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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-reas...query-for-you/

  • #4
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Quote Originally Posted by Sycren View Post
    On regards to linking to jquery, its often better to use googles hosted version. See more here: http://encosia.com/2008/12/10/3-reas...query-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.

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •