?
Solved

AJAX for extra input fields

Posted on 2007-10-03
3
Medium Priority
?
270 Views
Last Modified: 2012-08-14
I have a form that asks users to fill in the quantity of an item they have sold. The form has about 20 products, each with a text input field to enter the quantity. I now find that I also need to capture each item's serial number.

I would like to design the form so that if the user enters 4 as the quanity purchased, four text input fields appear below the original, to accept the serial number information.

I need the AJAX to show the appropriate input fields for the serial numbers and to allow server side verification of the serial numbers as they are entered.

My current input variables are arrays: e.g. <input type='text' name='prod[PC900]' value='' size='6'>

I would prefer the serial number be a compound array. e.g. prod_serial[PC900][1], prod_serial[PC900][2].

I am already using some AJAX on the page using Rafael Dohms brilliant autocomplete script for the company field, and I have used some other AJAX code on my site (although not on this page), but they have been modifiations of published scripts. I am not a Java/AJAX guru myself.  

I am using PHP for the server side.

I really appreciate your help.

0
Comment
Question by:birwin
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 20005724
Using http://www.xajaxproject.org/ it shpould be easy to accomplish:


<input type=text' name='prod[PC900]' value='' size='6' onchange="xajax_addSerials('PC900', this.value, xajax.getFormValues('formId'));"><div id="PC900Serials"><div>

function addSerials($prod, $num, $formdata)
{
    $result = '';
    for ($i= 0; $i <= $num; ++$i) {
       $result .= '<input name="prod_serial['.$prod.']['.$i.']">';
    }
    $objResponse = new xajaxResponse();
    $objResponse->assign($prod . "Serials","innerHTML", $result);
    return $objResponse;
}

Read the tutorial/demos for integration xajax into your php-scripts
0
 
LVL 6

Author Comment

by:birwin
ID: 20012077
I tried to set this up, but I am having trouble getting xajax to work. I have installed it, and I can get the examples to work and as far as I can determine, I am setting it up according to the examples, but I keep getting an error "Fatal error: Call to undefined method xajax::processRequests()"

Can you give me the full xajax code to make this work?

Also my site is templaed, so I need to be able to load the variable $display with any displayed output or $head for any code that appears in the head of the document.

Brian

I will gladly award more points, or if you are available freelance, I can hire you to complete the code for me.
0
 
LVL 6

Author Comment

by:birwin
ID: 20019091
Dear hernst42:

As luck would have it, my clent changed their mind and no longer want this option.

I'll still try hacking through xajax, since it seems to be a very useful program.

Thank you for your solution.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question