samedi 29 mai 2021

Get a dynamic input to populate an array and display randomly

I've got some code that currently successfully displays a random quote to users with the below code.

<script type="text/javascript">

var q = ['“The only reason I am successful is because I have stayed true to myself.”-Lindsey Stirling', '“To send light into the darkness of men’s hearts—such is the duty of the artist.” -Robert Schumann', '“I know that the most joy in my life has come to me from my violin.” -Albert Einstein, physicist and amateur violin player','“When you play a violin piece, you are a storyteller, and you’re telling a story.”-Joshua Bell','“Music is about devotion, and knowing when to be free.”-Leonidas Kavakos','“"Life" is a like myriad of perpetually ever-changing sound waves. "Living it" is like enjoying listening to this unrepeated orchestra and comfortably jamming along.”-Bo Ratiwat','“Playing a violin is, after all, only scraping a cats entrails with horsehair.”-Alan Watts','“Love is not love, without a violin playing goat.”-Julia Roberts','“When you play a violin piece, you are a storyteller, and you are telling a story.”-Joshua Bell','“Violin playing is a physical art with great traditions behind it.”-Vanessa Mae','"A table, a chair, a bowl of fruit and a violin; what else does a man need to be happy?"-Albert Einstein','If I do not practice one day, I know it; two days, the critics know it; three days, the public knows it."-Jascha Heifetz','"I am not handsome, but when women hear me play, they come crawling to my feet."-Niccolo Paganini'];

var elem = document.getElementById("quotes_contact");
var inst = setInterval(change, 10000);
change();
function change() {
    var min=0;
    var max=q.length - 1;
    var random =Math.floor(Math.random() * (+max - +min)) + +min;
    elem.innerHTML = q[random];
}

But, the website has a functionality to add a quote which should be displayed, therefore I now need the code to pull the quotes from this input form (dynamically), rather than having to update the hard coded array of quotes.

Can anyone help me work out how to get this dynamic input into my random quote visualiser? Thanks!!

This is the code in the quotes file...

  @if(count($quote)>0)
                <div class="row margin-adjust">
                   <div class="col-lg-12">
                        <div class="card-box table-responsive">
                            <table id="datatableCustom" class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Name</th>
                                        <th>Quote</th>
                                        <th class="control-label">Action</th>
                                    </tr>
                                </thead>
                                    <tbody>
                                    <?php $count = count($quote); ?>
                                    @for($i=0; $i<$count; $i++)
                                        <tr>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td class="tabactions">
                                                <a onclick="deleteQuote()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
                                            </td>
                                        </tr>
                                    @endfor
                                </tbody>
                            </table>
                       </div>
                    </div>
                </div>
            @else
                <div class="row margin-adjust">
                   <div class="col-lg-12">
                        <div class="card-box table-responsive">
                            <div class="no_data">
                                No Quote Data.<br>
                            </div>
                       </div>
                    </div>
                </div>
            @endif



Aucun commentaire:

Enregistrer un commentaire