Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Ajax help for a dummy...add line in form
Old 05-17-2007, 04:13 PM Ajax help for a dummy...add line in form
angele803's Avatar
Perfectly Imperfect

Posts: 1,774
Name: Stephanie
Location: Oklahoma
Trades: 2
I have taken several programming classes over the past couple of years, and recently started to try to learn javascript. I get the "big picture" logic of javascript, but am having trouble. Anyway, I am working on a form for internal company use. Basically it is an order form.
We will have a row in a form for the product being ordered. This row will look kind of like this:
Quantity Description 1st Color 2nd Color Unit Price Amount

The problem is this...for each order, we will have an undetermined number of products. Therefore, we will need a way to add a "row" to this form. I think the best way to do this would be with Ajax???

I have tried to search for ways to do this, but I feel like a big dummy. Can someone dumb down the process for doing this for me?
Thanks!
angele803 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-21-2007, 06:59 AM Re: Ajax help for a dummy...add line in form
jito's Avatar
MY LIFE IS 'i' LIFE

Posts: 565
Name: surajit ray
Location: inside the heart of my friends
Trades: 0
Not sure about what you want. If you want to create html elements dynamically you can use DOM. check if this is of any help
HTML Code:
<script>
function addElement() {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('val');
  var num = (document.getElementById('val').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = 'Text box'+num+': <input name="txt'+val+'">';
  ni.appendChild(newdiv);
}
</script>
<input type="hidden" value="0" id="val" />
<p><a href="#" onclick="addElement();">Add Some Elements</a></p>
<div id="myDiv"> </div>
__________________
I am not smart, that's why i don't act smart


Please login or register to view this content. Registration is FREE
jito is offline
Reply With Quote
View Public Profile
 
Old 05-21-2007, 08:31 PM Re: Ajax help for a dummy...add line in form
angele803's Avatar
Perfectly Imperfect

Posts: 1,774
Name: Stephanie
Location: Oklahoma
Trades: 2
Thanks for your help jito. I found this code example earlier, but am not really sure how to put it into my project.
This script does what I want, except I need to add form elements.
For example, if someone clicks the "Add some Elements", I need it to add a row of text boxes.

Here is my form so far:
http://motorxtremes.com/salesform.html
(I know there is a lot of work left to do)
When you scroll down to the unit information, I have 10 rows where a salesperson can enter a unit's information. Since I dont know how many items a person will order, I would like to let the salesperson add a "row" as they need them.
Does this make any sense??
angele803 is offline
Reply With Quote
View Public Profile
 
Old 05-22-2007, 03:36 AM Re: Ajax help for a dummy...add line in form
jito's Avatar
MY LIFE IS 'i' LIFE

Posts: 565
Name: surajit ray
Location: inside the heart of my friends
Trades: 0
you can add row of text boxes using the same method. As you have php script in back end just use the name attribute as an array like name='txtQty[]' to fetch the values.
HTML Code:
<script>
function addElement() {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('val');
  var num = (document.getElementById('val').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML='<label for="wf_Quantity" class="inlineLabel">Qty</label>';
  newdiv.innerHTML = '<span class="oneField"><label for="wf_Quantity" class="inlineLabel">Qty</label><input type="text" id="wf_Quantity" name="wf_Quantity[]" value="" size="2" class=""></span><span class="oneField"><label for="wf_Description" class="inlineLabel">Description</label><input type="text" id="wf_Description" name="wf_Description[]" value="" size="" class=""></span><span class="oneField"><label for="wf_1stColor" class="inlineLabel">1st Color</label><input type="text" id="wf_1stColor" name="wf_1stColor[]" value="" size="10" class=""></span><span class="oneField"><label for="wf_2ndColor" class="inlineLabel">2nd Color</label><input type="text" id="wf_2ndColor" name="wf_2ndColor[]" value="" size="10" class=""></span><span class="oneField"><label for="wf_UnitPrice" class="inlineLabel">Unit Price</label><input type="text" id="wf_UnitPrice" name="wf_UnitPrice[]" value="" size="10" class="validate-float"></span><span class="oneField"><label for="wf_Amount" class="inlineLabel">Amount</label><input type="text" id="wf_Amount" name="wf_Amount[]" value="" size="10" class="validate-float"></span>';
  ni.appendChild(newdiv);
}
</script>
<form name='myForm' action='#' method='POST'>
<input type="hidden" value="0" id="val" />
<p><a href="#" onclick="addElement();">+ Add products</a></p>
<div id="myDiv" class="inlineSection"></div>
</form>
__________________
I am not smart, that's why i don't act smart


Please login or register to view this content. Registration is FREE
jito is offline
Reply With Quote
View Public Profile
 
Old 05-22-2007, 11:36 AM Re: Ajax help for a dummy...add line in form
angele803's Avatar
Perfectly Imperfect

Posts: 1,774
Name: Stephanie
Location: Oklahoma
Trades: 2
That works! Thank you so much!!!




-talkupation added!
angele803 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Ajax help for a dummy...add line in form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15134 seconds with 12 queries