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 2 of 2

Thread: Two Issues

  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Two Issues

    I'm having a few issues here. First of all my buttons for the dropdowns are saying like for example TitlesDefened is not defined. It does this for the other 2 dropdowns. Another issue is that when the form submits it does the whole url.com/with the variables and values in the url.


    Code:
    <?php require ('php/bookings.php'); ?>
    
    <script type="text/javascript">
    $(document).ready(function() {
        $('div.message-error').hide();
        $('div.message-success').hide();
        $('li').remove('.titleName');
        $('li').remove('.stipulationName');
        $('li').remove('.characterName');
        
        function Competitors(matchNum) {
            
            function isDupe(which) {
                var result = false;
                $('ul#competitors'+ matchNum +' li').each(function(i, e) {
                    if ($(e).attr('characterID') == which) {
                        result = true;
                        return false; // break out of .each()
                    }
                });
                return result;
            }
            
            var characterID = $('#charactersDrop'+ matchNum +' option:selected').val();
            var characterName = $('#charactersDrop'+ matchNum +' option:selected').text();
            
            if (characterID > 0 && !isDupe(characterID)) {
                // Create the anchor element
                var anchor = $( '<a href="#">Remove</a>' );  
                
                // Create a click handler for the anchor element
                anchor.click( function() {
                    $( this ).parent().remove();
                    return false;  // makes the href in the anchor tag ignored
                } );
                
                // Create the <li> element with its text, and then append the anchor inside it.
                var li = $( '<li>' + characterName + '&nbsp;</li>' ).append( anchor );
                li.attr( 'characterID', characterID );
                
                // Append the new <li> element to the <ul> element
                $('#competitors'+ matchNum).append( li );
            }
        }
        
        function TitlesDefended(matchNum) {
            function isDupe(which) {
                var result = false;
                $('ul#titlesDefended'+ matchNum +' li').each(function(i, e) {
                    if ($(e).attr('titleID') == which) {
                        result = true;
                        return false; // break out of .each()
                    }
                });
                return result;
            }
            
            var titleID = $('#titlesDrop'+ matchNum +' option:selected').val();
            var titleName = $('#titlesDrop'+ matchNum +' option:selected').text();
            
            if (titleID > 0 && !isDupe(titleID)) {
                // Create the anchor element
                var anchor = $( '<a href="#">Remove</a>' );  
                
                // Create a click handler for the anchor element
                anchor.click( function() {
                    $( this ).parent().remove();
                    return false;  // makes the href in the anchor tag ignored
                } );
                
                // Create the <li> element with its text, and then append the anchor inside it.
                var li = $( '<li>' + titleName + '&nbsp;</li>' ).append( anchor );
                li.attr( 'titleID', titleID );
                
                // Append the new <li> element to the <ul> element
                $( '#titlesDefended'+ matchNum ).append( li );
            }
        }
        
        function StipulationsAdded(matchNum) {
            function isDupe(which) {
                var result = false;
                $('ul#stipulationsAdded'+ matchNum +' li').each(function(i, e) {
                    if ($(e).attr('stipulationID') == which) {
                        result = true;
                        return false; // break out of .each()
                    }
                });
                return result;
            }
            
            var stipulationID = $('#stipulationsDrop'+ matchNum +' option:selected').val();
            var stipulationName = $('#stipulationsDrop'+ matchNum +' option:selected').text();
            
            if (stipulationID > 0 && !isDupe(stipulationID)) {
                // Create the anchor element
                var anchor = $( '<a href="#">Remove</a>' );  
                
                // Create a click handler for the anchor element
                anchor.click( function() {
                    $( this ).parent().remove();
                    return false;  // makes the href in the anchor tag ignored
                } );
                
                // Create the <li> element with its text, and then append the anchor inside it.
                var li = $( '<li>' + stipulationName + '&nbsp;</li>' ).append( anchor );
                li.attr( 'stipulationID', stipulationID );
                
                // Append the new <li> element to the <ul> element
                $( '#stipulationsAdded'+ matchNum ).append( li );
            }
        }
        
        $("#bookerForm").validate({ 
            submitHandler: function(form) {
                var event = $("#event").val();
                var eventID = $("#eventID").val();
                for(i=1;i<<?php echo $numMatches ?>; i++) {
                    var matchNum = i + 1;
                    var matchTypeID = $('select#matchTypesDropID'+ matchNum).val();  
                    var liTitles = $('ul#titlesDefended'+ matchNum +' li');
                    var titlesIDList = "";
                    for( var i = 0; i < liTitles.length; i++ ) {
                        var liTitles = $( liTitles[ i ] );
                        
                        // only start appending commas in after the first characterID
                        if( i > 0 ) {
                            titlesIDList += ","; 
                        }
                        
                        // append the current li element's characterID to the list
                        titlesIDList += liTitles.data( 'titleID' );
                    }
                    var liStipulations = $('ul#stipulationsAdded'+ matchNum +' li');
                    var stipulationsIDList = "";
                    for( var i = 0; i < liStipulations.length; i++ ) {
                        var liStipulations = $( liStipulations[ i ] );
                        
                        // only start appending commas in after the first characterID
                        if( i > 0 ) {
                            stipulationsIDList += ","; 
                        }
                        
                        // append the current li element's characterID to the list
                        stipulationsIDList += liStipulations.data( 'stipulationID' );
                    }
                    var liCompetitors = $("ul#competitors li");
                    var competitorsIDList = "";
                    for( var i = 0; i < liCompetitors.length; i++ ) {
                        var liCompetitors = $( liCompetitors[ i ] );
                        
                        // only start appending commas in after the first characterID
                        if( i > 0 ) {
                            competitorsIDList += ","; 
                        }
                        
                        // append the current li element's characterID to the list
                        competitorsIDList += liCompetitors.data( 'characterID' );
                    }
                    var matchwriterID = $("select#matchWriterID").val();
                    var preview = $("textarea#preview").val();
                }
                
                var dataString = 'eventID=' + eventID + '&submitBooking=True';
                
                $('#bookerForm .field').each(function() {
                    dataString += '&matchNum=' + matchNum + '&matchTypeID=' + matchTypeID + '&titlesIDList=' + titlesIDList + '&stipulationsIDList=' + stipulationsIDList + '&competitorsIDList=' + competitorsIDList + '&matchWriterID=' + matchWriterID + '&preview=' + preview;
                });
                
                $.ajax({
                    type: "POST",
                    url: "processes/bookings.php",
                    data: dataString,
                    success: function() {
                        $('div.message-error').hide();
                        $("div.message-success").html("<h6>Operation successful</h6><p>" + event + " saved successfully.</p>");
                        $("div.message-success").show().delay(10000).hide("slow");
                        return true;
                    }
                });
                return false; 
            }   
        });
    });
    </script>
    
    <p class="listInfos">
        Card Lineup for <?php echo "".$event." on ".$bookingDate."" ?>
    </p>
            
    <!-- Form -->
    <form action="#" id="bookerForm" >
            <?php for( $i = 0; $i < $numMatches; $i++ ) { ?>
        <fieldset>
            <legend>Match #<?php echo $i+1 ?></legend>
            <div class="field required">
    			<label for="matchTypeDrop<?php echo $i+1 ?>">Match Type:</label>
                <select class="dropdown" name="matchTypeDrop<?php echo $i+1 ?>" id="matchTypeDrop<?php echo $i+1 ?>" title="Match Type <?php echo $i+1 ?>">
                    <option value="">- Select -</option>
                   <?php
                        mysqli_data_seek( $matchtypesResult, 0 );
                        while ( $row = mysqli_fetch_array ( $matchtypesResult, MYSQL_ASSOC ) ) { 
                            print "<option value=\"".$row['ID']."\">".$row['matchType']."</option>\r";
                        }
                    ?>
                </select>
            </div>
            <div class="field required">
    			<label for="titlesDefended<?php echo $i+1 ?>">Title On The Line:</label><ul id="titlesDefended<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul>
                <select class="dropdown" name="titlesDrop<?php echo $i+1 ?>" id="titlesDrop<?php echo $i+1 ?>" title="Titles Dropdown <?php echo $i+1 ?>" style="margin-left: 195px;">
                    <option value="">- Select -</option>
                   <?php
                        mysqli_data_seek( $titlesResult, 0 );
                        while ( $row = mysqli_fetch_array ( $titlesResult, MYSQL_ASSOC ) ) { 
                            print "<option value=\"".$row['ID']."\">".$row['titleName']."</option>\r";
                        }
                    ?>
                </select>
                <input type="button" value="Add Title" class="" onclick="TitlesDefended(<?php echo $i+1?>)"/>
            </div>
            <div class="field required">
    			<label for="stipulationsAdded<?php echo $i+1 ?>">Stipulation:</label><ul id="stipulationsAdded<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul>
                <select class="dropdown" name="stipulationsDrop<?php echo $i+1 ?>" id="stipulationsDrop<?php echo $i+1 ?>" title="Stipulations Dropown <?php echo $i+1 ?>" style="margin-left: 195px;">
                    <option value="">- Select -</option>
                   <?php
                        mysqli_data_seek( $stipulationsResult, 0 );
                        while ( $row = mysqli_fetch_array ( $stipulationsResult, MYSQL_ASSOC ) ) { 
                            print "<option value=\"".$row['ID']."\">".$row['stipulation']."</option>\r";
                        }
                    ?>
                </select>
                <input type="button" value="Add Stipulation" class="" onclick="StipulationsAdded(<?php echo $i+1 ?>)"/>
            </div>
            <div class="field required">
                <label for="competitors<?php echo $i+1 ?>">Competitors:</label><ul id="competitors<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul>
                <select class="dropdown" name="charactersDrop<?php echo $i+1 ?>" id="charactersDrop<?php echo $i+1 ?>" title="Characters Dropdown <?php echo $i+1 ?>" style="margin-left: 195px;">
                    <option value="">- Select -</option>
                   <?php
                        mysqli_data_seek( $charactersResult, 0 );
                        while ( $row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { 
                            print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";
                        }
                    ?>
                </select>
                <input type="button" value="Add Character" class="" onclick="Competitors(<?php echo $i+1 ?>)"/>
            </div>
            <div class="field required">
                <label for="matchWriter<?php echo $i+1 ?>">Match Writer:</label>
                <select class="dropdown" name="matchWriter<?php echo $i+1 ?>" id="matchWriter<?php echo $i+1 ?>" title="Match Writers <?php echo $i+1 ?>">
                    <option value="0">- Select -</option>
                   <?php
                        mysqli_data_seek( $matchwriterResult, 0 );
                        while ( $row = mysqli_fetch_array ( $matchwriterResult, MYSQL_ASSOC ) ) { 
                            print "<option value=\"".$row['ID']."\">".$row['name']."</option>\r";
                        }
                   ?>
                </select>
            </div>
            <div class="field required">
                <label for="preview<?php echo $i+1 ?>">Preview:</label>
                <textarea name="preview<?php echo $i+1 ?>" id="preview<?php echo $i+1 ?>" title="preview <?php echo $i+1 ?>"></textarea>
            </div>
        </fieldset>
            <?php
            }
            ?>
        <fieldset>
        <input type="hidden" name="eventID" id="eventID" value="<?php echo $eventID; ?>" />
        <input type="hidden" name="event" id="event" value="<?php echo $event; ?>" />
        <input type="submit" class="submit" name="submitBooking" id="submitBooking" title="Submit Booking" value="Submit Booking"/>
        </fieldset>
    </form>
    <!-- /Form -->
    
    <!-- Messages -->
    <div class="message message-error">
        <h6>Required field missing</h6>
        <p>Please fill in all required fields. </p>
    </div>
    <div class="message message-success">
        <h6>Operation succesful</h6>
        <p>Booking was added to the database.</p>
    </div>
    <!-- /Messages -->

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,788
    Thanks
    8
    Thanked 131 Times in 129 Posts
    Do you have a link to a live page? Since you are including a php file in this, there's no way for anyone to get a local version to test it.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis


  •  

    Posting Permissions

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