Create a user interface design for displaying alerts on a web

Currently, I am in the process of creating a form that includes a text box. One important validation I need to implement is that the name entered must be unique.

My approach involves accessing the parent div and modifying the entire HTML content within it.

Specifically, I am targeting the parent div and executing the following:


parentdiv.find('.child').html('<div class="form-group has-error has-feedback validateblockname"> <input type="hidden" id = "edit_tower_id" ><div class="alert alert-danger blocknamealert" role="alert" style="margin: 5px 0px 0px 0px;float: right; padding: 0;"> <code style="font-size: small;">Tower name already exists </code></div></input><label for="ProjectBlocks_block_name" class="control-label">Name</label><span class="glyphicon glyphicon-exclamation-sign form-control-feedback"></span><input type="text" class="form-control" id="ProjectBlocks_block_name" onblur="EditProjectBlocks.validateblockname();" onchange="EditProjectBlocks.validateblockname();"></div>'')                 

https://i.sstatic.net/ieiPY.png https://i.sstatic.net/n6Mwp.png

This snippet is related to the initial image display.


parentdiv.find('.child').html('<div class="form-group"><input type="hidden" id="edit_tower_id"><label for="ProjectBlocks_block_name" class="control-label">Name</label><input type="text" class="form-control" id="ProjectBlocks_block_name" onblur="EditProjectBlocks.validateblockname();" onchange="EditProjectBlocks.validateblockname();"></div>');

Is there a more efficient alternative to achieve this task?

Answer №1

To see a demonstration along with the source code, visit the link below:

http://jsfiddle.net/cse_tushar/QAePU/2/

For additional validation options, consider using the J Query validation plug-in. Follow this link for more information:

http://jqueryvalidation.org/

Answer №2

Embed the form you wish to upload into the parent div, giving it a specific ID, and hide it within the DOM structure...

When needed, make a copy of it using the clone() method and append or replace it within the parent div...

var duplicatedForm = $("#duplicateForm").clone();
$(duplicatedForm).appendTo("#targetContainer");

VIEW DEMO

Answer №3

If you're looking to create a customized confirmation dialog using jQuery, you can follow these steps:

Visit jQuery UI Dialog for reference

Here is an example of how you can create a custom confirm dialog:

// Function to display a confirm dialog
function confirmDialog(text, title, onConfirm, onCancel, okButton, cancelButton) {

    var dialogElement = createDialogElements(text);
    var response = false;
    
    // Set dialog title
    if (title !== undefined) {
        dialogElement.attr('title', title);
    } else {
        dialogElement.attr('title', 'Confirmation');
    }
    
    // Configure dialog options
    dialogElement.dialog({
        modal: true,
        width: 500,
        dialogClass: "custom-dialog-class",
        close: function () {
            dialogElement.remove();
        },
        buttons: [{
            text: okButton || "OK",
            click: function() {
                $(this).dialog("close");
                if (onConfirm !== undefined && onConfirm !== null) {
                    onConfirm();
                }
                response = true;
            },
        },
        {
            text: cancelButton || "Cancel",
            click: function() {
                $(this).dialog("close");
                if (onCancel !== undefined && onCancel !== null) {
                    onCancel();
                }
                response = false;
            }
        }]
    });
    
    return response;
}; 

// Function to create dialog content
function createDialogElements(text){
    var dialogElement = $(document.createElement('div'));
    dialogElement.addClass('custom-dialog-class');

    var messageParagraph = $(document.createElement('p'));
    messageParagraph.addClass('custom-dialog-message-class');
    messageParagraph.text(String(text));

    dialogElement.append(messageParagraph);
    
    return dialogElement;
}

Finally, you can trigger the confirm dialog by adding the following onClick event:

$(".trigger").click(function () {
    var url = $(this).attr('href');
    confirmDialog("Are you sure you want to proceed?", 'Confirmation',
        function () {
            window.location = url;
        });

    return false;
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent the execution of an event while another event is already running in jQuery

Two events are in play here: one with the onclick function which scrolls to a specific div upon menu item click, and the other utilizes the onscroll function to "highlight" the corresponding menu item when scrolling near the div. The burning question is: ...

dotdotdot.js is only functional once the window has been resized

For my website, I am attempting to add an ellipsis to multiline paragraphs that exceed a certain height. I have incorporated the dotdotdot jquery plugin from here. An odd issue arises when the page is refreshed, as the ellipsis does not appear until I res ...

attach jQuery extension to several components

After spending hours scouring the internet, I have yet to find a solution to my issue. The problem is that I have developed a plugin for creating a typing effect on any given element, and it works perfectly when applied to a single element. However, when I ...

When clicked, activate a different overlay div

I have an image that I want to enhance with some effects. I was able to add a hover overlay using a div. Now, I am looking to add an onclick event to change to another overlay div. Below is the code I have so far, or you can view the CodePen Here <d ...

Can double curly braces be added within an HTML attribute when using Vue?

Suppose I would like to include <input value='{{default}}'></input> in regular HTML. This will display a textbox with {{default}} as the default input. However, when attempting to achieve the same thing with Vue, it does not work as ...

Employing jQuery to populate information into an input field, yet encountering an issue where the data is not being successfully transmitted to

On my page, there is a form with an input box <input name="bid_price" id="bid_price" class="form-control"> If I manually enter a value, it gets posted successfully But when I try to insert a value using jQuery, it doesn't get posted, even tho ...

When you zoom in, the HTML elements tend to shift out of place

Spent the entire day yesterday attempting to make my page responsive while Zooming In, but I just can't seem to get it right. Even after adding height and weight, elements still get mixed up when zooming in on the page. I've scoured countless w ...

What methods do Google and Facebook use to manage user sessions effectively?

I'm looking to incorporate a session in my asp.net application that remains active until the user logs out. I've come across this feature on websites like Google, where the session persists even after a computer restart. How do they achieve this ...

Calculating and displaying the output on an HTML page: A step-by-step guide

Within my HTML, I have two values stored in Session Storage: "Money" and "Time". These values are based on what the user inputted on a previous page. For example, if someone entered that they need to pay $100 in 2 days. My goal is to generate a list that ...

Unable to save a string value from a function to MongoDB is unsuccessful

I've hit a roadblock. Working tirelessly to solve a persistent bug, but it feels like I'm getting nowhere. What am I missing? My goal is clear - once the user submits a form with the enctype of "multipart/form-data", I want to extract t ...

Stop the submission of a form using jQuery based on its unique identifier

When using the jQuery Ajax function to verify if a user email exists in the database during a jQuery change event, there are two possible outcomes in the Ajax response. If the user email does exist, an error message is displayed. In this scenario, I aim ...

I could use some input on the best way to make a background video fill the screen while incorporating overlay text

Struggling to make the background video fit perfectly on all devices and browsers? While it looks great in Chrome now, I'm still facing some clipping issues with IE Edge. Any experts out there who can offer their validation or suggest improvements? I ...

How can JSON data be passed to the Google Charts API?

I am currently working on a project that involves retrieving JSON data from a website and visualizing it on a live graph using the Google Charts API. Despite my efforts, I am unable to get the chart to display properly. Can someone please guide me in the r ...

Utilize Auth.currentSession() every 5 minutes within Vuex Store for automatic session management

I have been developing an application that makes frequent requests to our API, however, sometimes these requests result in expired tokens. I have explored different solutions such as calling Auth.currentSession and setting the header before sending the re ...

Error: foobar is not defined within this scope (anonymous function)

I'm facing an issue with a JavaScript file hosted on a domain called foobar.com. at http://foobar.com/static/js/main.js: $(document).ready(function() { function foobar(bar){ $.ajax({ url: "/site/foo/", ...

Minimize unnecessary rendering in React when toggling between tabs

I am currently working on a React application that utilizes material-ui to generate tabs. <div className={classes.root}> <AppBar position="static"> <Tabs value={value} onChange={handleChange}> <Tab label="Item One" /> ...

What could be causing such a significant impact on the row height in a CSS table when a tiny image is inserted next to an input box?

Currently, I am facing a unique challenge while setting up a form using CSS tables. The issue is best explained through a fiddle: http://jsfiddle.net/GdgV4/6/ In the third row, you'll notice that adding an image with a height less than the input box ...

Assign value to an element in an array using the value from another element

Is it possible in Javascript to set the value of one array element based on another without changing both elements? Specifically, how can I only modify arr[1] while leaving other elements unchanged? arr[0] = {i: 0}; arr[1] = arr[0]; arr[1]['summ&apos ...

Angular state correctly maps to the controller but is not reflected in the HTML

I'm currently in the process of setting up a basic Angular application, something I've done many times before. I have defined a home state and another state for a note-taking app, but I am facing an issue where neither state is displaying or inje ...

Looping through ng-repeats, extracting checked checkbox values in Angular

I am currently dealing with multiple nested ng-repeats in my project, and the third level down consists of a group of checkboxes. Initially, I receive an array of options for these checkboxes, which I handle with the following code snippet: <div class= ...