Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Please help

  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Please help

    I'm not sure if I'm in the right place or not, but I am in desparate need of some help. I have this code:

    Code:
    <script type="text/javascript">
    
    
    $(document).ready(function(){
    	$('#add').click(function() {
    	alert('test');
    	});
    	$("form#exercise").submit(function() {
    	// we want to store the values from the form input box, then send via ajax below
    	var activity     = $('#activity').attr('value');
    		$.ajax({
    			type: "POST",
    			url: "newActiveProc.php",
    			data: "activity="+ activity +"&func=search",
    			success: function(activity){
    				$("span#results").html(activity);
    
    			}
    		});
    	return false;
    	});
    
    });
    </script>
    As you can see by the highlighted portion, the user is alerted once they make a selection. It should go something like this:

    [Add to table] Football
    [Add to table] Basketball
    [Add to table] Baseball

    Once they click the 'add to table' button, their selection should be added to a table that is at the bottom of the page. So far, all I've been able to do is generate an alert box, but I know thats not right. Any information anyone has would be helpful. Thanks in advance.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Dude. Please don't cross-post stuff. It makes me all confused and disorientated.

    Also, thread titles like "Please help" aren't useful. Read the posting guidelines and you'll get a much better response to your questions.

    Anyway; your question. Please can you post the HTML that you're currently using? What you're trying to do isn't hard, but we need to know the structure of both the elements that you'll be getting the content out of, and the table you'll be dropping it in to.

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts
    I'm sorry. I will try to be descriptive as possible. I am working on a page called. activities.php. Here is the basic structure of activities.php:

    Code:
    <?php
    
    <script type="text/javascript">
    
    
    $(document).ready(function(){
    	$('#add').click(function() {
    	alert('test');
    	});
    	$("form#exercise").submit(function() {
    	// we want to store the values from the form input box, then send via ajax below
    	var activity     = $('#activity').attr('value');
    		$.ajax({
    			type: "POST",
    			url: "newActiveProc.php",
    			data: "activity="+ activity +"&func=search",
    			success: function(msg){
    				$("span#results").html(activity);
    
    			}
    		});
    	return false;
    	});
    
    });
    </script>
    
    
    <style type="text/css">
    .mydate{
    color:#00F;
    text-decoration:underline;
    cursor:pointer;
    }
    </style>
    
    <script type="text/javascript">
    function displayDate(d){
    var date=new Date();
    var D=date.getDate();
    date.setDate(D+d);
    var YYYY=date.getFullYear();
    var MM=date.getMonth()+1;
    MM<10?MM='0'+MM:null;
    var DD=date.getDate();
    DD<10?DD='0'+DD:null;
    var span=document.getElementById('date');
    span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY;
    }
    onload=function(){displayDate(0)};
    </script>
    
    <h1>Food Diary</h1>
    
    <div class="full">
    <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="date" style="font-size:2em;"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br />
    <a href="#" onclick="displayDate(0);return false;">Today</a>
    </center>
    	</div>
    
    
    <div class="full">
    <center><form name="exercise" id="exercise" method="POST" action="newActiveProc.php">
    <table>
    	<tr>
        	<td><h3>Add an Activity</h3></td>
    	</tr>
    	<tr>
        	<td><input name="NewSearchString" style="width: 100px" type="text"/>&nbsp;&nbsp;<input type="button" value="Search" /> </td>
    	</tr>
        <tr>
        	<td>
            	<select name="activity" id="activity" name="activity">
                	<option value="_">Activity Browse...</option>
                    <option value="all">All Activities</option>
                    <option value="biking">Biking</option>
                    <option value="condition">Conditioning</option>
                    <option value="dancing">Dancing</option>
                    <option value="fish">Fishing & Hunting</option>
                    <option value="Home">Home Activities</option>
                    <option value="misc">Miscellaneous</option>
                    <option value="music">Music Playing</option>
                    <option value="occupation">Occupation</option>
                    <option value="running">Running</option>
                    <option value="sports">Sports</option>
                    <option value="walking">Walking</option>
                    <option value="water">Water Activities</option>
                    <option value="winter">Winter Activities</option>
    			</select> &nbsp;&nbsp;<input type="submit" value="Submit"/>
    		</td>
    	</tr>
    </table>
    </form></center>
    
    <br /><br />
    <form name="add" id="add" method="POST" action="newActiveProc.php">
    <span id="results"></span>
    </form>
    <table width="100%">
       	<tr bgcolor="#66CC33">
        	<td><div>Activity</div></td>
            <td><div>Specific Activity</div></td>
            <td><div>Time (hh:mm)</div></td>
            <td><div>Calories Burned</div></td>
            <td><div>Distance</div></td>
            <td><div>Units</div></td>
            <td><div>Delete</div></td>
    	</tr>
        <tr bgcolor="#66CC33">
        	<td><div></div></td>
            <td><div>Calories Burned Today</div></td>
            <td><div>24:00</div></td>
            <td><div class="Float">2,525</div></td>
            <td class="cp_Distance"><div></div></td>
            <td class="cp_Unit"><div></div></td>
            <td class="cp_Delete"><div></div></td>
    	</tr>
        <tr>
        	<td><div>jogging</div></td>
            <td><div>general, moderate effort</div></td>
            <td class="cp_TimeSpent"><input type="text" value="0:15"/></td>
            <td class="cp_Calories"><div class="Float">21</div></td>
            <td class="cp_Distance"><input type="text" value=""/></td>
            <td class="cp_Unit"><select>
            		<option value="mile">mile</option>
                	<option value="Km">km</option>
                	<option value="M">m</option>
                	<option value="Yard">yrd</option>
                	<option value="Feet">ft</option>
                </select></td>
            <td class="cp_Delete"><img src="images/delete.gif" border="0" /></td>
    	</tr>
        <tr>
        	<td><div>backpacking</div></td>
            <td><div></div></td>
            <td class="cp_TimeSpent"><input type="text" value="0:01"/></td>
            <td class="cp_Calories"><div class="Float">8</div></td>
            <td class="cp_Distance"><input type="text" value=""/></td>
            <td class="cp_Unit"><select>
            		<option value="mile">mile</option>
                	<option value="Km">km</option>
                	<option value="M">m</option>
                	<option value="Yard">yrd</option>
                	<option value="Feet">ft</option>
                </select></td>
            <td class="cp_Delete"><img src="images/delete.gif" border="0" /></td>
    	</tr>
        <tr>
        	<td><div>Lifestyle</div></td>
            <td><div><div style="display: inline; padding-right: 3px">Seated, Some Movement</div><a href="ActivityLifestyle.html?_a_Date=1273968000."><div style="display: inline">(Customize)</div></a></div></td>
            <td class="cp_TimeSpent"><div class="Float">23:24</div></td>
            <td class="cp_Calories"><div class="Float">2,468</div></td>
            <td class="cp_Distance"><div></div></td>
            <td class="cp_Unit"><div></div></td>
            <td class="cp_Delete"><div></div></td>
    	</tr>
        <tr bgcolor="#66CC33">
        	<td><div></div></td>
            <td><div>Calories Burned Today</div></td>
            <td class="cp_TimeSpent"><div>24:00</div></td>
            <td class="cp_Calories"><div class="Float">2,525</div></td>
            <td class="cp_Distance"><div></div></td>
            <td class="cp_Unit"><div></div></td>
            <td class="cp_Delete"><div></div></td>
    	</tr>
    </table>
    
    
    </div>
    ?>
    The alert in bold is just a test to make sure the code is working, which it is. Ideally, the user is supposed to select an activity from the database to be added to the table in a page named activtiesProc.php; This is the structure of activitiesProc.php:

    Code:
    <?php
    session_start();
    $con = mysql_connect("localhost","fffinc_admin","F00dFitness")
    	or die('Could not connect: ' . mysql_error());
    
    $select = mysql_select_db("fffinc_ind",$con)
    	or die('Could not select fffinc_ind');
    
    $activity  = $_POST['activity'];
    
    ?>
    
    
    <h1>Food Diary</h1>
    
    <div class="full">
    	<center><a href="#"><img src="images/left_arrow.png" border="0" />&nbsp;Yesterday</a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
        <font size="+1"><strong>Entries for <a href="#">Today - Date</a></strong></font>
    
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="#">Tomorrow &nbsp;<img src="images/right_arrow.png" border="0" /></a></center>
        </div>
    
    <div class="full">
    <form name="exercise" id="exercise" method="POST" action="activitiesProc.php">
    
    <center><table>
    	<tr>
        	<td><h3>Add an Activity</h3></td>
    	</tr>
    	<tr>
        	<td><input name="NewSearchString" style="width: 100px" type="text"/>&nbsp;&nbsp;<input type="submit" value="Search" /> </td>
    	</tr>
        <tr>
        	<td>
            	<select name="activity">
                	<option value="_">Activity Browse...</option>
                    <option value="all">All Activities</option>
                    <option value="biking">Biking</option>
                    <option value="condition">Conditioning</option>
                    <option value="dancing">Dancing</option>
                    <option value="fish">Fishing & Hunting</option>
                    <option value="Home">Home Activities</option>
                    <option value="misc">Miscellaneous</option>
                    <option value="music">Music Playing</option>
                    <option value="occupation">Occupation</option>
                    <option value="running">Running</option>
                    <option value="sports">Sports</option>
                    <option value="walking">Walking</option>
                    <option value="water">Water Activities</option>
                    <option value="winter">Winter Activities</option>
    			</select> &nbsp;&nbsp;<input type="submit" value="Submit" />
    		</td>
    	</tr>
    </table> </center>
    <br /><br />
    
    <table id="green-button">
    
    <?php
    $results = mysql_query("SELECT Type, Name, calBurned FROM exercise WHERE Type = '$activity'");
    $count = mysql_numrows($results);
    
    mysql_close($con);
    
    $i = 0;
    
    while ($i < $count) {
    	$type = mysql_result($results,$i,"Type");
    	$name = mysql_result($results,$i,"Name");
    	$calBurned = mysql_result($results,$i,"calBurned");
    ?>
    
    
    
    		<tr>
    	    	<td><a class='green-button pcb' href='activities.php?AddToLog=something"'><span>Add to Activity Log</span></a></td>
    	        <td><strong><? echo $name; ?></strong></td>
    	</tr>
    
    
    <?
    	$i++;
    	}
    ?>
    </table>
    <br /><br />
    
    <table width="100%">
       	<tr bgcolor="#66CC33">
        	<td><div>Activity</div></td>
            <td><div>Specific Activity</div></td>
            <td><div>Time (hh:mm)</div></td>
            <td><div>Calories Burned</div></td>
            <td><div>Distance</div></td>
            <td><div>Units</div></td>
            <td><div>Delete</div></td>
    	</tr>
        <tr bgcolor="#66CC33">
        	<td><div></div></td>
            <td><div>Calories Burned Today</div></td>
            <td><div>24:00</div></td>
            <td><div class="Float">2,525</div></td>
            <td class="cp_Distance"><div></div></td>
            <td class="cp_Unit"><div></div></td>
            <td class="cp_Delete"><div></div></td>
    	</tr>
        <tr>
        	<td><div>jogging</div></td>
            <td><div>general, moderate effort</div></td>
            <td class="cp_TimeSpent"><input type="text" value="0:15"/></td>
            <td class="cp_Calories"><div class="Float">21</div></td>
            <td class="cp_Distance"><input type="text" value=""/></td>
            <td class="cp_Unit"><select>
            		<option value="mile">mile</option>
                	<option value="Km">km</option>
                	<option value="M">m</option>
                	<option value="Yard">yrd</option>
                	<option value="Feet">ft</option>
                </select></td>
            <td class="cp_Delete"><img src="images/delete.gif" border="0" /></td>
    	</tr>
        <tr>
        	<td><div>backpacking</div></td>
            <td><div></div></td>
            <td class="cp_TimeSpent"><input type="text" value="0:01"/></td>
            <td class="cp_Calories"><div class="Float">8</div></td>
            <td class="cp_Distance"><input type="text" value=""/></td>
            <td class="cp_Unit"><select>
            		<option value="mile">mile</option>
                	<option value="Km">km</option>
                	<option value="M">m</option>
                	<option value="Yard">yrd</option>
                	<option value="Feet">ft</option>
                </select></td>
            <td class="cp_Delete"><img src="images/delete.gif" border="0" /></td>
    	</tr>
        <tr>
        	<td><div>Lifestyle</div></td>
            <td><div><div style="display: inline; padding-right: 3px">Seated, Some Movement</div><a href="ActivityLifestyle.html?_a_Date=1273968000."><div style="display: inline">(Customize)</div></a></div></td>
            <td class="cp_TimeSpent"><div class="Float">23:24</div></td>
            <td class="cp_Calories"><div class="Float">2,468</div></td>
            <td class="cp_Distance"><div></div></td>
            <td class="cp_Unit"><div></div></td>
            <td class="cp_Delete"><div></div></td>
    	</tr>
        <tr bgcolor="#66CC33">
        	<td><div></div></td>
            <td><div>Calories Burned Today</div></td>
            <td class="cp_TimeSpent"><div>24:00</div></td>
            <td class="cp_Calories"><div class="Float">2,525</div></td>
            <td class="cp_Distance"><div></div></td>
            <td class="cp_Unit"><div></div></td>
            <td class="cp_Delete"><div></div></td>
    	</tr>
    </table>
    </div>
    ?>
    The problem I'm having is that though the alert is working, is not ideal in this situation. It would be ideal to have the activity the user submits in activities.php sent to activitiesProc.php, which the ajax/jquery code is setup to do, but it's not 100% functioning. I don't know if I need to be some type of jquery event handler there or not. I inherited this code and have most of it functioning properly. I do realize there is a lot of filler information in there and I do apologize. Any information you all could offer towards a feasible solution would be greatly appreciated. Thank you in advance.


  •  

    Posting Permissions

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