1

Likely not the best approach; (I know) but I have several toggle buttons within a very interactive website that when toggled load the form fields and radio buttons below; nested in a div, all of the toggles are pulling in the same exact form -- I am seeking a way to write or pull in the below within a AJAX call or include of somesort, php or iFrame if I must -- so that I can update 1 file and all of my toggles will reflect the updated. Preferring a solution to keep most of current code, rather then absolutely rewriting everything for the change.

$(function() {
$('#toggle3').click(function () {
    $('.toggle').hide('1000');
    $('.toggle').html('<div style="font-size: 12px; color: #000; text-align: left; padding-left: 15px; padding-top: 20px;"><form><br>Back wheel color?<br><input type="radio" name="backwheel" value="Purple"><span style="color: #B500E4"><img src="http://ecx.images-amazon.com/images/I/41S7CRzpV3L._AA160_.jpg" style="max-height: 100px;">Purple</span><br><input type="radio" name="backwheel" value="White">White</br><input type="radio" name="backwheel" value="Light Blue"><span style="color: #74A1C4;">Light Blue</span></br><input type="radio" name="backwheel" value="Blue">Blue</br><input type="radio" name="backwheel" value="Tan">Tan</br><input type="radio" name="backwheel" value="Grey">Grey</br><input type="radio" name="backwheel" value="Pink">Pink</br><input type="radio" name="backwheel" value="Red">Red</br><input type="radio" name="backwheel" value="Yellow">Yellow</br><input type="radio" name="backwheel" value="Black">Black</br><input type="radio" name="backwheel" value="Green"><span style="color:#44CA2C">Green</span></br></form></span></form><br>Front Wheel (if different)<br><form><br>Front wheel color?<br><input type="radio" name="backwheel" value="Purple"><span style="color: #B500E4">Purple</span><br><input type="radio" name="backwheel" value="White">White</br><input type="radio" name="backwheel" value="Light Blue"><span style="color: #74A1C4;">Light Blue</span></br><input type="radio" name="backwheel" value="Blue">Blue</br><input type="radio" name="backwheel" value="Tan">Tan</br><input type="radio" name="backwheel" value="Grey">Grey</br><input type="radio" name="backwheel" value="Pink">Pink</br><input type="radio" name="backwheel" value="Red">Red</br><input type="radio" name="backwheel" value="Yellow">Yellow</br><input type="radio" name="backwheel" value="Black">Black</br><input type="radio" name="backwheel" value="Green"><span style="color:#44CA2C">Green</span></br></form></div><div id="next"><a href="#" id="toggle3">Check Out!<img src="http://northbrooklyncollective.com/wp-content/uploads/2013/11/519629-129_ArrowRight-128.png" class="tool"></a></div>');
$('.toggle').slideToggle('1000');

return false; 
    });
  });

Recent attempt:

$(document).ready(function() {

$('#toggle3').click(function(){
    var $tog = $('.toggle');
    $.ajax({
        url: '/BikeCustom/shine/script.php',
        type: 'GET', //this is default anyway, only for verbosity
        success: function (fields){
            $tog.html(fields);
            $tog.slideToggle(1000);
        }
  });
});

script.php = nested div in original.

jQuery:

<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>

1 Answer 1

1
$('#toggle3').click(function(){
    var $tog = $('.toggle');
    $tog.hide(1000);
    $.ajax({
        url: 'path/to/my/script.php',
        type: 'GET', //this is default anyway, only for verbosity
        success: function (fields){
            $tog.html(fields);
            $tog.slideToggle(1000);
        }
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so much, I love this! Although it doesn't work for me and the toggle dies?
The above worked with the removal of $ on all instances of tog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.