Jump to content

Jquery change function


Xtremer360

Recommended Posts

not sure if I"m doing this correctly so seeing who can see or tell me if I'm doing this wrong.

 

Say you chose an option from select box it would go into the events table and see that there's not been another event with that id so it'll return 1 and put it inside the text field called Label and when the user fills out the rest of the form it'll put 1 for the label field in the database table when the form is submitted then say the next week rolls around and the user clicks on that same option again and it goes to the events table and sees that there's an occurance of that show via the matching eventids and grabs all the labels with that matching eventid which at this point is only 1 so it would add 1 to that number and return 2 to the Label form text field.

 

form page

$('#eventid').change(function() {
      var eventid = $("select#eventid").val();
      var dataString = 'eventid='+ eventid;
      $.ajax({
        type: "POST",
        url: "processes/booking.php",
        data: eventid,
        success: function(data) {
        $('#label').append(data);
        }
        });  
    });

<div class="field required">
    			<label for="eventid">Select Event</label>
                <select class="dropdown" name="eventid" id="eventid" title="Select Event">
                <option value="0">- Select -</option>
                <option value="0">** Recurring Events **</option>
                <?php
                    $query = 'SELECT id, eventname FROM eventnames WHERE eventtype = "Recurring"';
                    $result = mysqli_query ( $dbc, $query ); // Run The Query
                    while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { 
                        print "<option value=\"".$row['id']."\">".$row['eventname']."</option>\r";
                    }
                    ?>
                <option value="0">** Singular Events **</option>
                <?php
                    $query = 'SELECT id, eventname FROM eventnames WHERE eventtype = "Singular"';
                    $result = mysqli_query ( $dbc, $query ); // Run The Query
                    while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { 
                        print "<option value=\"".$row['id']."\">".$row['eventname']."</option>\r";
                    }
                    ?>
                <option value="0">** Pay Per View Events **</option>
                <?php
                    $query = 'SELECT id, eventname FROM eventnames WHERE eventtype = "Pay Per View"';
                    $result = mysqli_query ( $dbc, $query ); // Run The Query
                    while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { 
                        print "<option value=\"".$row['id']."\">".$row['eventname']."</option>\r";
                    }
                    ?>
                </select>
    			<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
    		</div>
            <div class="field required">
			<label for="label">Event Label</label>
			<input type="text" class="text" name="label" id="label" title="Label" readonly="readonly" />
                <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
		</div>

 

processes/booking.php

$eventid = (int)$_GET['eventid'];
$result = mysqli_query("SELECT * FROM `events` WHERE `event_id` = '$eventid'");
$list = mysqli_num_rows($result);
$label = $list + 1;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.