Results 1 to 8 of 8

Thread: How to do this?

  1. #1
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to do this?

    I'm designing a form for users to submit. Basically, the form allows users to enter rebate form links. However, the number of rebates varies. So I'd like to have user enter a number first, then a list of input text fields appear underneath the number entered.

    I am wondering how to do this???

    thanks a lot!!

  2. #2
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I suppose the easiest method would be with Ajax (XMLHttp to access the...), PHP (the MySQL functions, to mess with the database), MySQL (well its the DB) I don't know how ( or if its possible) to connect to a DB with Ajax. Try checking them out, a combination of them wouldn't be hard. The form could be:

    Code:
    <input type="text" name="rebatepart1" onChange="check();">
    Then the Ajax would be something like:

    Code:
    if (window.XMLHttpRequest)
    { 
    xmlhttp=new XMLHttpRequest();
    } 
    else 
    if (window.ActiveXObject)
    {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } 
    
    function RSchange() {
    if (xmlhttp.readyState==1) {
    document.getElementById('contentdiv').innerHTML="Loading..."
    }
    else if (xmlhttp.readyState==4) {
    document.getElementById('contentdiv').innerHTML=xmlhttp.responseText
    }
    }
    function check() {
    var data="rebatepart1=" + rebatepart1;
    var rebatepart1=getElementByName("rebatepart1");
    
    if (xmlhttp) {
    d=document
    xmlhttp.open("POST", "somephp.php", true);
    xmlhttp.onreadystatechange=RSchange
    xmlhttp.send(data)
    }
    }
    The PHP and DB are up to you. Let me know if you need help,

    Tim

  3. #3
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a lot for the code.

    I doubt if I need to connect to mysql database, because the number of extra input fields depends on the number entered, ,right?

    Here's my HTML code:

    Code:
        <input type="text" name="number_rebates" value="how many rebates?"> //user enters number of extra fields here, then extra input fields shall be generated like the one below with different names (field1, field2, field3, etc).
    
    
        <input name="field1" type="text" value="rebate1" size="30" maxlength="150">
    Thank you!

  4. #4
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I'm not sure I get what you are saying. Are you saying you want a box for them to tell how many rebates they have? I misunderstood and though you meant have a box where you type in the first number then depending on that number a box appeared below. I didn't quite see the logic in it, but hey your idea not mine. Anyways, if thats what you meant, then you'd best wait for someone who knows JavaScript well, no reason for me to give you an overly complicated PHP/Ajax script to accomplish something JavaScript can do. But, I'm not familiar with JavaScript (its similar to PHP, but I always fail at it). Sorry, good luck.

    Tim

    EDIT: I thought you mean't you type in the first number (say 2) then something is updated and depending on what number say you could have a box below with something special about it, then at the end submit and whatever your doing collects them all and assembles it into a number or whatever.
    Last edited by TimFA; 02-21-2008 at 04:53 AM. Reason: Made more clear

  5. #5
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    exactly, you got what I'm trying to say here:

    having a user to enter a number first, say he has 3 rebates. Then three input text fields will be generated on the same page without redirecting him. If you know how to do this with AJAX, that would be very nice if can show me how to implement it.

    Thanks, I appreciate it.

    Tony

  6. #6
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    See the problem is, I'm not familiar with using JavaScript/Ajax to do the writing to the page. However using a Ajax request and a PHP while() auto decreasing loop I can generate fields as field 1,2,3,4 BUT it would be much more efficient to not use PHP. I hate to give you something overly complicated. However, if you want it I'd be more than happy to make it for you.

  7. #7
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes, I will appreciate your code. I like AJAX, because it loos cool.

    Thanks a lot!!! I appreciate your time and help

  8. #8
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    Sure man.

    Attached is a PHP/HTML page, I had to remove the Ajax some reason it refused to send the data to the PHP...anyways, this should do. You need to submit, but everything appears to work.

    Tim

Bookmarks

Posting Permissions

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