"...Remember being a youngster, mom or dad telling you "close the door"? Well the same applies to HTML ...."

Go Back   Webmaster Forums > Code Forum > HTML Forum

Reply
 
Thread Tools Rate this Webmaster Discussion
Old 10-22-2009, 08:03 AM   #1
Bigmous
Junior Member
 
Join Date: Dec 2008
Location: Sydney, Australia
Webmaster Discussions: 27
Rep Power: 11
Bigmous is on a distinguished road
Exclamation Help required urgently

I'm in need of some help. currently working on a major php project for uni and am slightly stuck on a form feature that is required.

i've got a drop down menu and an input box next to it. once the user clicks the add button, I need a new drop down and input box to be generated under it. this new row of fields will occur each time they click on the add.


Bigmous is offline   Reply With Quote
Old 10-22-2009, 09:26 AM   #2
coothead
bald headed old fart
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Webmaster Discussions: 580
Rep Power: 67
coothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud of
Re: Help required urgently

Hi there Bigmous,

here is an example that I have just knocked up...
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<style type="text/css">
#theForm div {
    clear:both;
    width:320px;
    height:20px; 
    padding:10px;
    border:1px solid #333;
    margin:4px auto;
 }
#theForm input,#theForm select {
    float:left;
    margin:0 5px 10px;
 }
.blue {
    background-color:#ccf;
 }
.red {
    background-color:#fcc;
 }
</style>

<script type="text/javascript">
if(window.addEventListener){
   window.addEventListener('load',init,false);
 }
else { 
if(window.attachEvent){
   window.attachEvent('onload',init);
  }
 }

function init(){

  c=0;
  d=2
  optLength=3;
  opt=[];
  df=document.forms[0];

df[2].onclick=function(){
  addElements();
  }
 }

function addElements() {

   c++;
   dv=document.createElement('div');
   dv.setAttribute('id','container'+c);
if(c%2==0) {
   dv.className='blue';
 }
else {
   dv.className='red';
 }
   sel=document.createElement('select');
   sel.setAttribute('name','select'+c);

for(k=0;k<optLength;k++){
   d++;
   opt[k]=document.createElement('option');
   opt[k].setAttribute('value',d);
if(k==0){
   opt[k].appendChild(document.createTextNode('---options---'));
 }
else {
   opt[k].appendChild(document.createTextNode('option '+d));
 }
   sel.appendChild(opt[k]);
 }
   dv.appendChild(sel);

   inp=document.createElement('input');
   inp.setAttribute('name','input'+c);
   inp.setAttribute('type','text');

   dv.appendChild(inp);

   document.forms[0].appendChild(dv);
 }
</script>

</head>
<body>

<form id="theForm" action="#">

<div id="container0" class="blue">

<select name="select0">
 <option value="0">---options---</option>
 <option value="1">option 1</option>
 <option value="2">option 2</option>
</select>

<input name="input0" type="text">
<input type="button" value="add">

</div>

</form>

</body>
</html>
__________________
coothead is offline   Reply With Quote
Old 10-24-2009, 06:02 AM   #3
Bigmous
Junior Member
 
Join Date: Dec 2008
Location: Sydney, Australia
Webmaster Discussions: 27
Rep Power: 11
Bigmous is on a distinguished road
Re: Help required urgently

Thanks heaps mate, the only problem i'm trying to figure out now is how i can keep the add button next to or under the last 1

Cheers,

Mous
Bigmous is offline   Reply With Quote
Old 10-24-2009, 06:45 AM   #4
coothead
bald headed old fart
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Webmaster Discussions: 580
Rep Power: 67
coothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud of
Re: Help required urgently

Hi there Mous,

this can be easily done with a slight modification.
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<style type="text/css">
#theForm {
    margin:0;
 }
#theForm div {
    clear:both;
    width:264px;
    height:20px; 
    padding:10px;
    border:1px solid #333;
    margin:4px auto;
 }
#theForm input,#theForm select {
    float:left;
    margin:0 5px 10px;
 }
#button {
    width:284px;
    margin:auto;
 }
#add  {
    float:right;
 }
.blue {
    background-color:#ccf;
 }
.red {
    background-color:#fcc;
 }
</style>

<script type="text/javascript">
if(window.addEventListener){
   window.addEventListener('load',init,false);
 }
else { 
if(window.attachEvent){
   window.attachEvent('onload',init);
  }
 }

function init(){

  c=0;
  d=2
  optLength=3;
  opt=[];
  df=document.forms[0];

document.getElementById('add').onclick=function(){
  addElements();
  }
 }

function addElements() {

   c++;
   dv=document.createElement('div');
   dv.setAttribute('id','container'+c);
if(c%2==0) {
   dv.className='blue';
 }
else {
   dv.className='red';
 }
   sel=document.createElement('select');
   sel.setAttribute('name','select'+c);

for(k=0;k<optLength;k++){
   d++;
   opt[k]=document.createElement('option');
   opt[k].setAttribute('value',d);
if(k==0){
   opt[k].appendChild(document.createTextNode('---options---'));
 }
else {
   opt[k].appendChild(document.createTextNode('option '+d));
 }
   sel.appendChild(opt[k]);
 }
   dv.appendChild(sel);

   inp=document.createElement('input');
   inp.setAttribute('name','input'+c);
   inp.setAttribute('type','text');

   dv.appendChild(inp);

   document.forms[0].appendChild(dv);
 }
</script>

</head>
<body>

<form id="theForm" action="#" >

<div id="container0" class="blue">

<select name="select0">
 <option value="0">---options---</option>
 <option value="1">option 1</option>
 <option value="2">option 2</option>
</select>

<input name="input0" type="text">

</div>

</form>

<div id="button">
<input id="add" type="button" value="add">
</div>

</body>
</html>
__________________
coothead is offline   Reply With Quote
Old 10-24-2009, 06:58 AM   #5
Bigmous
Junior Member
 
Join Date: Dec 2008
Location: Sydney, Australia
Webmaster Discussions: 27
Rep Power: 11
Bigmous is on a distinguished road
Wink Re: Help required urgently

omg ofcourse, so very simple!!! lol thanks heaps, i think lack of sleep and all my c++, java and php projects are finally getting to me. haha how could i of missed that.

thanks again
Bigmous is offline   Reply With Quote
Old 10-24-2009, 07:05 AM   #6
coothead
bald headed old fart
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Webmaster Discussions: 580
Rep Power: 67
coothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud of
Re: Help required urgently

No problem, you're very welcome, Mous.
__________________
coothead is offline   Reply With Quote
Reply

Bookmarks

Tags
required, urgently

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Webmaster Discussions
Thread Webmaster Discussion Starter Forum Replies Last Post
Help required about media itmodo Archive 0 06-26-2009 07:21 AM
Freelancers wanted urgently that specialize in the following IT fields... ServiceNinja Internet Services 0 07-12-2006 09:52 PM
Wanted Urgently : Website tuankeedin Websites For Sale 2 02-20-2006 03:39 AM


All times are GMT -5. The time now is 08:55 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.