SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How do I point the HTML form entries to another database?

    I'm trying to expand on a tutorial where Jonathan Stark creates a database using JS, CSS, and JQuery.

    A complete explanation of the code can be found in chapters 4 and 5 here:
    Building Android Apps with HTML, CSS, and JavaScript (sets up the HTML).
    Building Android Apps with HTML, CSS, and JavaScript (sets up the DB storage).

    Stark uses a form for the user to enter data, then the attached js file inserts the data into the SQLite database:

    HTML Code:
    <div id="createEntry">
        <div class="toolbar">
            <h1>New Setup</h1>
            <a class="button cancel" href="#">Cancel</a>
        </div>
        <form method="post">
            <ul class="rounded">
                <li><img src="picture.png">
    			<br>FRONT Shock Mounting, arm: <input type="text" placeholder="TAP HERE TO ENTER" name="shockMountingArm" id="shockMountingArm" 
                     autocapitalize="off" autocorrect="off" autocomplete="off" /></li>
                <li>FRONT Piston: <input type="number" placeholder="" name="piston" id="piston" 
                     autocapitalize="off" autocorrect="off" autocomplete="off" /></li>
                <li>FRONT Shock Oil wt.: <input type="number" placeholder="" name="shockOil" id="shockOil" 
                     autocapitalize="off" autocorrect="off" autocomplete="off" /></li>
    			<li>FRONT Shock Springs:
    			 <select name="shockSpring" id="shockSpring">
    			 	<option value="green">green</option>
    				<option value="blue">blue</option>
    				</select></li>
     <!--doesn't work. Text entered in by user does not save to DB:
    			<li>FRONT Shock Springs, OTHER: <input type="text" placeholder="" name="shockSpring" id="shockSpring"
    				autocapitalize="off" autocorrect="off" autocomplete="off" /></li>	--> 
    
    			<li><input type="submit" class="submit" name="action" value="Save Settings" /></li>
            </ul>
        </form>
    </div>
    The form is processed by a database script on another page, as indicated by the header:
    <script type="text/javascript" src="kilo.js"></script>

    In kilo.js, the following grabs the field's data:

    Code:
    function createEntry() {
        var date = sessionStorage.currentDate;
        var calories = $('#calories').val();
        var food = $('#food').val();
        db.transaction(
            function(transaction) {
                transaction.executeSql(
                    'INSERT INTO entries (date, calories, food) VALUES (?, ?, ?);', 
                    [date, calories, food], 
                    function(){
                        refreshEntries();
                        jQT.goBack();
                    }, 
                    errorHandler
                );
            }
        );
        return false;
    }
    function refreshEntries() {
        var currentDate = sessionStorage.currentDate;
        $('#date h1').text(currentDate);
        $('#date ul li:gt(0)').remove();
        db.transaction(
            function(transaction) {
                transaction.executeSql(
                    'SELECT * FROM entries WHERE date = ? ORDER BY food;', 
                    [currentDate], 
                    function (transaction, result) {
                        for (var i=0; i < result.rows.length; i++) {
                            var row = result.rows.item(i);
                            var newEntryRow = $('#entryTemplate').clone();
                            newEntryRow.removeAttr('id');
                            newEntryRow.removeAttr('style');
                            newEntryRow.data('entryId', row.id);
                            newEntryRow.appendTo('#date ul');
                            newEntryRow.find('.label').text(row.food);
                            newEntryRow.find('.calories').text(row.calories);
                            newEntryRow.find('.delete').click(function(){
                                var clickedEntry = $(this).parent();
                                var clickedEntryId = clickedEntry.data('entryId');
                                deleteEntryById(clickedEntryId);
                                clickedEntry.slideUp();
                            });
                        }
                    }, 
                    errorHandler
                );
            }
        );
    }
    My question: how can I redirect the form to a different database script on a different or same page as this database code? I want to have multiple forms going to different tables, and I want the database scripts kept separate. I just don't understand how the form data knows to be inserted into this database.

    If I duplicate kilo.js, rename it kilo2.js and use different field names, and attach it to the forms page following kilo.js, then kilo.js is ignored and the original form does not work.

    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is my post unclear? Or is the answer: "impossible!"

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    Is my post unclear? Or is the answer: "impossible!"
    I think that it's because Android is an unknown entity when it comes to most of us.

    Moving thread to the more specific "Developing for Mobile Devices" where there may be people who can help.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks! This script works just fine in a browser on the desktop, so the device is irrelevant. Maybe it belongs in the database section of the forums.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    Thanks! This script works just fine in a browser on the desktop, so the device is irrelevant. Maybe it belongs in the database section of the forums.
    No, I doubt that. The database people tend to spit the dummy whenever they see programming code. I'll bring it back to the JavaScript forum as that's the next appropriate place.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The mixture of JS and Sql is the problem, huh?


Tags for this Thread

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
  •