• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

how can i make Update button function?

April 10, 2020 by

Questions › how can i make Update button function?
0
Vote Up
Vote Down
Garmaine asked 4 years ago

Actually , I'm trying to make an update button , once i click on it , should display the row data in the input field, and then i will edit the inputs after that i will press on submit button and the final result should be the row with the updated info that i have added .

<body>
    <div class="container pt-5 pb-5">
        <h1 class="pb-5 pl-3 font-weight-bold">BookMark</h1>
        <hr>
        <div class="body m-auto text-center py-5">
            <h2 class="py-2">Bookmark your favorite sites</h2>
            <form class="w-75 m-auto" id="myForm">
                <div class="form-group">
                    <label for="Site_Name" class="py-2">Site Name</label>
                    <input type="text" class="form-control" id="siteName" placeholder="Bookmark Name">
                </div>
                <div class="form-group">
                    <label for="Site_URL" class="py-2">Site URL</label>
                    <input type="text" class="form-control" id="siteUrl" placeholder="website URL">
                </div>
                <button id="sub" class="btn btn-primary">Submit</button>
            </form>
        </div>
        <div class="container mt-3">
            <div class="row shadow-none p-3 mb-5 bg-light rounded">
                <div class="col">
                    <div id="bookmarkCon"></div>
                </div>
            </div>
        </div>
        <hr>
        <div class="footer">
            <p>&copy;2019 Bookmarker Inc.</p>
        </div>
    </div>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/main.js"></script>
</body>
//Javascript
var bookMname = document.getElementById("siteName");
var bookUrl = document.getElementById("siteUrl");
var btn = document.getElementById("sub");
var bookMarks;

if (localStorage.getItem("BookStorage") == null) {
    bookMarks = [];
}

else {
    bookMarks = JSON.parse(localStorage.getItem("BookStorage"));
    displayData();
}



btn.onclick = function () {
    addBookMark();
    displayData();
    reset();

}

function addBookMark() {

    if (bookMname.value != "" && bookUrl.value != "") {
        var bookMark = {
            bookMarkName: bookMname.value,
            url: bookUrl.value,
        }

        bookMarks.push(bookMark);
        localStorage.setItem("BookStorage", JSON.stringify(bookMarks))
    }
    else {
        alert("Please fill the empty fields");
    }


}


function displayData() {

    /**local var */
    var data = "";

    for (var i = 0; i < bookMarks.length; i++) {

        data += "<div><span class='mr-5 font-weight-bold h1 text-uppercase'>" + bookMarks[i].bookMarkName + "  " + "</span><span>" + ' <a class="btn btn-primary mr-4" target="_blank" href="' + bookMarks[i].url + '">Visit</a> ' + "</span><span>" + '<a class="btn btn-danger mr-4" href="#" onclick="handleDelete(' + i + ');">Delete</a> ' + "</span> <span>" + '<a class="btn btn-info mr-4" href="#" onclick="Update()">Update</a> ' + "</span></div>"

    }

    document.getElementById("bookmarkCon").innerHTML = data;
}

function reset() {
    document.getElementById("myForm").reset();

}

function handleDelete(index) {
    bookMarks.splice(index, 1);
    localStorage.setItem("BookStorage", JSON.stringify(bookMarks));
    displayData();
}

// update button

function Update() {
    for (var i = 0; i < bookMarks.length; i++) {



    }

}

your help is highly appreciated , if it possible make it with a simple way , as i'm a i'm a beginner in java script. thnaks in advance

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: javascript, json, local-storage

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023