The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

multiple functions in one javascript?

Hi, I'M new to javascript and i seriously need help urgently. Here are the problems.

1. I have 2 functions inside one javascript but however when i call this 2 method on different buttons when i click on it both give me this error, "Object Expected". However, if i remove one of the function the another function works. How am i going to create multiple functions in one javascrip?

2. I will like to create dynamic fields for multiple different naming txtbox.
for e.g. user will key in the No. of people information to enter, if user key in 1, Name txtbox, Sex txtbox and Add txtbox will appear. On the other hand if user key in 2 it will appear 2 sets of the txtbox.

With the second question, I presume that you'll want to update the number of people that the form has, so if someone changes the number to a higher or lower value, then the form should update itself.

Code html4strict:

<formid="peopleInfo"><p><label>How many people to enter data for? <inputtype="text"name="people"></label></p></form>

With the following code, I've made sure that the functions are small and easy to understand. This will help you to more easily understand what they do, and more importantly, make it easier to adjust their behaviour to fit your needs.

These are some helper functions that are used by the rest of the code.

Code javascript:

function getFieldNumber(el){// Takes from "name2" the value "2"// and returns it as a number 2var digits = el.name.match(/\.*(\d+)/)[1];return parseInt(digits,10);}function upUntilParentTag(el, tag){// Climbs the DOM until it gets to a child with a given parent tag.// Useful for going up until you get to a top section.while(el.parentNode.nodeName!== tag){
el = el.parentNode;}return el;}function insertAfter(target, els){// The opposite of insertBefore// places content directly after the targetif(target.nextSibling){
target.parentNode.insertBefore(els, target.nextSibling);}else{
target.parentNode.appendChild(els);}}