What is the best way to implement a dynamic form within a fieldset using jQuery Mobile?

I am trying to dynamically insert a form inside a fieldset. This is my approach using jQuery:

$(document).on("pagebeforeshow", "#mainPage", function () {
                if (sessionStorage.login_state != 1) {
                    alert('You don\'t have permission to login here!');
                    window.location.href = 'index.html';
                } else {
                    var name = sessionStorage.name;
                    var email = sessionStorage.email;
                    var dit = sessionStorage.dit;
                    $('#userinfo-form').append("<form method='POST' action='index.html'>" +
                            "<lable for='i_name'>Name : </label>" +
                            "<input class=\"ui-disabled\" type='text' id='i_name' name='i_name' value='" + name + "' data-mini='true' />" +
                            "<lable for='i_email'>Email : </label>" +
                            "<input class=\"ui-disabled\" type='text' id='i_email' name='i_email' value='" + email + "' data-mini='true' />" +
                            "<lable for='i_dit'>DIT : </label>" +
                            "<input class=\"ui-disabled\" type=\"text\" id=\"i_dit\" name='i_dit' value='" + dit + "' data-mini='true' />" +
                            "<lable for='i_newPassword'>New Password : </label>" +
                            "<input class=\"ui-disabled\" type='password' id='i_newPassword' name='i_newPassword' value='' data-mini='true' />" +
                            "<a id=\"user_edit\" class=\"ui-btn-c ui-mini ui-btn btn-primary ui-icon-mail ui-shadow\" >Edit</a>" +
                            "<a id=\"user_update\" class=\"show-page-loading-msg ui-btn btn-primary ui-shadow ui-hide\" data-textonly=\"false\" data-btntype=\"updateinfo\" data-textvisible=\"true\" data-msgtext=\"Please wait...\" type=\"button\"  data-theme=\"c\">Update Info</a>"+
                            "</form>").enhanceWithin();
                }
            });

This is the corresponding HTML code:

<div data-role="panel" id="p_userinfo" data-position="right" data-theme="c" data-swipe-close="true" >
                <h2>User Info</h2>
                <div class="ui-field-contain" id="userinfo_field">
                    <fieldset id="userinfo-form" data-role="controlgroup" data-type="horizontal">
                    
                    </fieldset>
                </div>
            </div>

However, I'm facing issues with this code as it does not display anything on the page. Interestingly, changing the CSS to set display:block for the form in the browser makes the form visible.

Answer №1

For those with their HTML body code enclosed within a <div id="content"> (as described in the official jQM documentation @ ), a simple solution is to execute ("#content").trigger("refresh") after inserting the HTML into the DOM. Feel free to reach out if you require more details :)

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

Tips on enabling users to update SQL database data on an HTML webpage

The mySQL database stores user input from a form like this: <form action="demo.php" method="POST"/> <p><label>title:</label> <input type="text" name="titulo" required/></p> ... $value = $_POST['titulo'] ; ...

What is the best way to handle JSON data errors when a value is undefined?

I am currently working on a piece of code that displays JSON data in HTML. However, if a value is undefined, it doesn't display anything. How can I handle this error so that if a value is undefined, it will show "N/A" instead of breaking the code? ...

Bootstrap 5 and Vue 3 team up to create a stunning masonry layout

I've been struggling to find a proper solution for implementing a masonry layout in Vue 3 with Bootstrap. I tried using Bootstrap 5 cards with the Masonry CDN, but it resulted in squeezed and overlapping cards, failing to achieve the desired layout. I ...

The functionality to clear the input search text upon clicking is malfunctioning

Why isn't this basic script working as expected? It has worked fine in the past, but now it's not functioning properly. <form name="form1"> <input type="search" placeholder="Search..." required="required" onfocus="if(this.value == &ap ...

Invisibility of form data on new page - PHP and Javascript

I have a webpage with multiple hyperlinks. Each hyperlink should redirect the user to a new page with the URL sent as POST data. What I can do: 1. Open the new page successfully. The issue I'm facing: 1. On the new page, I cannot access the URL ...

Struggles with arranging HTML header components

I've been attempting to insert a Twitter logo into the header of my website (which is styled using Bootstrap CSS), but unfortunately, it's causing some alignment issues. My initial goal was to position them next to each other, however, they ended ...

Hover effect on Angular Material Stepper

Is there a way to apply CSS styles to a specific step (Angular material stepper) when hovering over it? I have attempted to set the styles on the elements .mat-step-header and mat-step, as well as applying a custom CSS class, but so far nothing has seeme ...

The main page wrapper will be centered on all devices except for tablets, where it will appear

I have set up a main container, #main, for my page content with a central position. It is positioned absolutely to create some space above the container. Centering is achieved using negative margins and left:50% instead of margin:auto. However, the issue a ...

I'm trying to create a transparent v-card, but for some reason it's not turning out the way I want

How can I make the v-card transparent while keeping its content opaque using CSS? card.vue <v-card class="cardColor"> <v-card-text> TEXT </v-card-text> <v-card-actions> <v-btn color="prima ...

Error message for something that is conceptualized as an unexpected mistake in a sector unrelated to J

https://i.stack.imgur.com/FBmia.png Whenever I try to run the following code snippet, I encounter an error: var request = 'randomcode'; $.post('../php/forms/postrequest.php', 'type=' + request, function (response) { var ...

Is it necessary to define all presentational images in CSS?

Lately, I've been diving into the world of (X)HTML & CSS and have come to understand that HTML is meant for structure while CSS is used for presentation. It makes me wonder if a significant portion of images on websites are more about enhancing p ...

What is the best method for incorporating dynamic page transitions when navigating between individual pages?

Let's say I have the following pages: red.html blue.html green.html My goal is to create links from red.html to blue.html and red.html to green.html. When attempting to use page anchors and iframes, I encountered an issue where scrolling from red.h ...

What steps should I follow to generate a table using Ajax and Javascript when a button is clicked?

After spending hours following various tutorials and exploring previously asked questions, I am struggling to make this work. My HTML page looks like this: <!DOCTYPE html> <html> <head> <link type="text/css" rel="styleshee ...

Ensure that both textarea and pre elements have equal dimensions and line wrapping behavior in Internet Explorer

I am in the process of implementing a dynamic textarea that resizes automatically, based on a technique discussed in this article: Alistapart: Expanding Textareas (2011). The idea is quite straightforward: by using a pre element to mirror the input in the ...

Turn off the scroll function while loading a webpage

Here is the script for my preloader: $(window).load(function() { $("#loading").fadeOut(1000); I want to prevent scrolling while the "loading" is still visible, and then enable it again after the fade out completes. ...

Preventing opening new tabs when clicking on "_blank" links in Selenium VBA

When using HTML, the code to create a link that opens in a new browser tab is as follows: <a target="_blank" id="mylink" herf="www.google.com">google</a> In VBA, you can use the following code to click on the link using the driver object ...

Expansive background spanning the width within a container

Here is the code I am working with: <div class="wrapper"> <div class="full-width"> <div class="header"> <a href=""> <img src="img/logo.png" alt="Logo" class="logo img-responsive" /> ...

What is the best way to ensure a textarea remains expanded when the parent element is in focus?

I have successfully implemented a textarea box that expands upon click and retracts when it loses focus. However, I am facing an issue where if the textbox is already in expanded form, I want it to stay expanded if the user clicks anywhere within the cont ...

Prevent dragging functionality in ckeditor

Currently, I am encountering a problem with my ckeditor. The issue arises when I load a full page of HTML into the ckeditor. While it loads and displays correctly, I am seeking a way to restrict users from editing the alignment of the content, only allow ...

Utilizing Ajax and jQuery to verify the initial password input in real-time as the user types

My goal is to create a Change Password page where users can enter their original password and have it instantly checked for correctness without the need for page refresh. I want to display a checkbox image next to the text box when the password is correct. ...