1

ループによって吐き出されるフォームがあります。その目的は、車両の在庫を管理しやすい方法で表示することなので、何でも編集できます。私の問題は、非表示/表示をクリックするとフォームが送信されることです。空の場合、ホームページにリダイレクトされます

以前は機能していました。コードがGoogleからjqueryを取得できるようにすると実際に機能しますが、それは根本的な問題ではないと確信していますが、修正されているようです

これがフォームの私のコードです

<?php
function manage_vehicles($soldvalue)
{
    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    echo '<div class="span12">
    <a href=""><button id="deleteall" name="deleteall" class="btn btn-danger" type="submit" >Delete</button></a> &nbsp;';
    if ($actual_link == 'http://localhost/cardealerwins/admin.php?manage_vehicles')
    {
        echo '<a href="admin.php?manage_sold"><button href="admin.php?manage_sold" id="managesold" name="deleteall" 
        class="btn btn-success" type="submit" >Manage sold vehicles</button></a>';
    } 
    else if ($actual_link == 'http://localhost/cardealerwins/admin.php?manage_sold')
    {
        echo '<a href="admin.php?manage_vehicles"><button href="admin.php?manage_vehicles" id="managesold" name="deleteall" 
        class="btn" type="submit" >Manage active vehicles</button></a>';
    }
    echo '</div>';
    //get the total number of vehicles active in the database to loop through them and displaying them to manage
    $query = mysql_query("SELECT COUNT('auto_id') FROM `auto` WHERE `sold` = $soldvalue");
    $all = mysql_result($query, 0);  //store the value so we can run this loop accordingly
    $counter = 1;
    $auto_id = 0; //auto id equal to zero as starting point, it will increase randomly to as many vehicles it will diplay
    while ($counter <= $all)  //ie run for every car
    {
        $fields = 'auto_id, year, make, model, engine, sound_system,mileage, price, vin, att1, att2, att3, att4, att5, att6, att7, att8, 
        att9, att10, att11, att12, att13, att14, att15, picture1, picture2, picture3, picture4, picture5, picture6, picture7, picture8, 
        picture9, picture10, picture11, picture12';
        //check where the auto id is greater then the previously one according to $auto_id which increments
        $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `auto` WHERE `auto_id` > $auto_id AND `sold` = $soldvalue"));

        $auto_id = $data['auto_id'];  //here is the magic, we set the auto id to the current one being spitted out so it follows through
        //now with all the $data retrieved from the database we can print car by car with its unique info and ids
        echo '<div id="displaycarwrap" class="span3 container">
        <input type="checkbox" value="'. $data['auto_id'] .'" class="deletebox" /><br />
        <a href="#"><img src="' . $data['picture1'] . '"></a>
        <form action="admin/tool/editvehicle.php" method="post">
            <ul>
                <li>
                    <br><b>Price</b>: <input name="price" type="text" class="span2" value="' . $data['price'] . '">
                </li>
                <li>
                    <button name="delete" class="btn btn-danger" type="submit" >Delete Vehicle</button>
                </li>
                <li>
                    <button name="sold" class="btn btn-success" type="submit" >Mark as Sold</button>
                </li>
                <li>
                    <button class="btn btn-primary" name="editpictures" type="submit" >Edit Pictures</button>
                </li>
                <li>
                    <button type="submit" name="editauto" class="btn  btn-inverse" >Apply Changes</button>
                </li>
            </ul>
            <button class="show_hide btn btn-mini icon-th-list" href="#" rel="slidingDiv'. $counter .'">View details</button>
            <div id="slidingDiv'. $counter .'" class="toggleDiv" style="display: none;">
            <ul> <br />
                <li><b>Year</b>:<br /><input type="text" name="year" value="' . $data['year'] . '" class="span2"></li>
                <li><b>Make</b>: <br /><input type="text" name="make" value="' . $data['make'] . '" class="span2"></li>
                <li><b>Model</b>: <br /><input type="text" name="model" value="' . $data['model'] . '" class="span2"></li>
                <li><b>Mileage</b>: <br /><input type="text" name="mileage" value="' . $data['mileage'] . '" class="span2"></li>
                <li><b>Engine</b>:<br /> <input type="text" name="engine" value="' . $data['engine'] . '" class="span2"></li>
                <li><b>Stereo</b> <br /><input type="text" name="sound_system" value="' . $data['sound_system'] . '" class="span2"></li>
                <li><b>Attribute 1 </b> <input type="text" name="att1" value="' . $data['att1'] . '" class="span2"></li>
                <li><b>Attribute 2</b> <input type="text" name="att2" value="' . $data['att2'] . '" class="span2"></li>
                <li><b>Attribute 3</b> <input type="text" name="att3" value="' . $data['att3'] . '" class="span2"></li>
                <li><b>Attribute 4</b> <input type="text" name="att4" value="' . $data['att4'] . '" class="span2"></li>
                <li><b>Attribute 5</b> <input type="text" name="att5" "value="' . $data['att5'] . '" class="span2"></li>
                <li><b>Attribute 6</b> <input type="text" name="att6" value="' . $data['att6'] . '" class="span2"></li>
                <li><b>Attribute 7</b> <input type="text" name="att7" value="' . $data['att7'] . '" class="span2"></li>
                <li><b>Attribute 8</b> <input type="text" name="att8" value="' . $data['att8'] . '" class="span2"></li>
                <li><b>Attribute 9</b> <input type="text" name="att9" value="' . $data['att9'] . '" class="span2"></li>
                <li><b>Attribute 10</b> <input type="text" name="att10" value="' . $data['att10'] . '" class="span2"></li>
                <li><b>Attribute 11</b> <input type="text" name="att11" value="' . $data['att11'] . '" class="span2"></li>
                <li><b>Attribute 12</b> <input type="text" name="att12" value="' . $data['att12'] . '" class="span2"></li>
                <li><b>Attribute 13</b> <input type="text" name="att13" value="' . $data['att13'] . '" class="span2"></li>
                <li><b>Attribute 14</b> <input type="text" name="att14" value="' . $data['att14'] . '" class="span2"></li>
                <li><b>Attribute 15</b> <input type="text" name="att15" value="' . $data['att15'] . '" class="span2"></li>
                <li><b>Vin</b> <input type="text" name="vin" value="' . $data['vin'] . '" class="span2"></li>
                <li><input type="text" name="auto_id" value="' . $data['auto_id'] . '" class="span2" readonly><li>
            <ul>

            </div>
        </form>
        </div>';
        $counter++; //used for the while loop it self and for classes id uniqueness for javascript
    }
}

?>

ここに私のjqueryのコードがあります:

//function to hide the extra info for the cars in manage vehicles
(function ($) {
    $.fn.showHide = function (options) {

    //default vars for the plugin
        var defaults = {
            speed: 250,
            easing: '',
            changeText: 0,
            showText: 'View details',
            hideText: 'close'

        };
        var options = $.extend(defaults, options);

        $(this).click(function () {
// optionally add the class .toggleDiv to each div you want to automatically close
                      $('.toggleDiv:hidden').slideUp(options.speed, options.easing);
             // this var stores which button you've clicked
             var toggleClick = $(this);
             // this reads the rel attribute of the button to determine which div id to toggle
             var toggleDiv = $(this).attr('rel');
             // here we toggle show/hide the correct div at the right speed and using which easing effect
             $(toggleDiv).slideToggle(options.speed, options.easing, function() {
             // this only fires once the animation is completed
             if(options.changeText==1){
             $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
             }
              });

          return false;

        });

    };
})(jQuery);



$(document).ready(function(){

   $('.show_hide').showHide({
        speed: 250,  // speed you want the toggle to happen
        easing: '',  // the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
        changeText: 1, // if you dont want the button text to change, set this to 0
        showText: 'View details',// the button text to show when a div is closed
        hideText: 'Close' // the button text to show when a div is open

    });




});

私のコンソールは私に言っています:

Uncaught ReferenceError: google is not defined 

私はそれとは何の関係もないと思います

キャッチされていない referenceError のエラー

Uncaught ReferenceError: google is not defined
jQuery.fn.extend.addEventListener
jQuery.fn.(anonymous function)
$.fn.showHide managevehicles.js:20
(anonymous function) managevehicles.js:46
fire jquery2.js:3074
self.fireWith jquery2.js:3186
jQuery.extend.ready jquery2.js:433
completed jquery2.js:104
Uncaught ReferenceError: google is not defined
jQuery.fn.extend.addEventListener
jQuery.fn.(anonymous function)
(anonymous function) scripts.js:10
jQuery.event.dispatch jquery2.js:5116
elemData.handle jquery2.js:4787
4

2 に答える 2

0

使用している表示/非表示ボタンは、デフォルトで送信ボタンとして機能します。実際、フォーム内のすべての<button> 要素は、クリックするとフォームを送信します。

変更してみる

    <button class="show_hide btn btn-mini icon-th-list" href="#" rel="slidingDiv'. $counter .'">View details</button>

to <input type="button"> 

他の属性はそのまま

(または) または、このコードを jquery に追加して、送信がデフォルトで無効になるようにします

$('.show_hide').click(function(e){
     e.preventDefault();
});
于 2013-08-14T20:38:20.890 に答える
0

次のように、event.preventDefault() メソッドを使用して URL リダイレクトをキャンセルできます。

$(this).click(function (event) {
  //Cancel the url redirection caused by clicking the a tag.
  event.preventDefault();

// optionally add the class .toggleDiv to each div you want to automatically close
                      $('.toggleDiv:hidden').slideUp(options.speed, options.easing);
             // this var stores which button you've clicked
             var toggleClick = $(this);
             // this reads the rel attribute of the button to determine which div id to toggle
             var toggleDiv = $(this).attr('rel');
             // here we toggle show/hide the correct div at the right speed and using which easing effect
             $(toggleDiv).slideToggle(options.speed, options.easing, function() {
             // this only fires once the animation is completed
             if(options.changeText==1){
             $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
             }
              });

          return false;

        });

preventDefault http://api.jquery.com/event.preventDefault/の JQuery ドキュメントの例を参照してください。

于 2013-08-14T20:42:36.763 に答える