Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8637383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:27:59+00:00 2026-06-12T10:27:59+00:00

… but if the value is originally empty like the value can not be

  • 0

… but if the value is originally empty like “” the value can not be changed using the same key !

function loadDialog(link, e, ajaxRequest) {

    e.preventDefault();
    var $title = link.innerHTML;
    var $contenturl = $(link).attr('href');
    var $dialog = $('<div id="MyDialog"></div>');

    // Read value from hidden input field
    var templateIdValue = $('input[name=TemplateId]').val();     

    // Change the value: This will always and only happen the 2nd time I come here,
    // the first time the templateIdValue will always be empty
    if (templateIdValue != '') {
        templateIdValue = 777;
    }

    $dialog.load($contenturl).data('templateIdKey', templateIdValue).dialog({
        title: $title,
        autoOpen: true,
        modal: true,               
        buttons: {
            "OK": function () {debugger;
                ajaxRequest($(this), $('form', this));
            },
            "Cancel": function () {
                $dialog.dialog("close");
            }
        }
    });
}

When the 2nd time the templateIdValue is changed to 777

I come to this code:

Here I retrieve again the value and it should be 777. But its NOT. its empty !

@model ITMS.Web.Models.UnitViewModel

@*Remote Validation*@
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {
        var templateId = $('#MyDialog').data('templateIdKey');
        $('input[name=TemplateId]').val(templateId);      
    }); 

</script>

@using (Html.BeginForm("Create", "Unit"))
{ 
     @Html.ValidationSummary(false)
    <p class="editor-label">@Html.LabelFor(model => model.Name)</p>
    <p class="editor-field">@Html.EditorFor(model => model.Name)</p>
    <p class="editor-field">@Html.ValidationMessageFor(model => model.Name)</p> 

    @Html.HiddenFor(x => x.TemplateId)    
}

How can I change the value of the key I passed the first time with the .data() method?

UPDATE

  // Does not cache the ajax requests to the controller e.g. IE7/8/9 is doing that...
    $.ajaxSetup({ cache: false });

    $(document).ready(function () {
        $('#OpenTemplate').click(function (event) { loadDialog(this, event, openTemplate); });
        $('#CreateTemplate').click(function (event) { loadDialog(this, event, createTemplate); });
        $('#DeleteTemplate').click(function (event) { loadDialog(this, event, deleteTemplate); });

        $('#CreateUnit').click(function (event) { loadDialog(this, event, createUnit); });
        $('#DeleteUnit').click(function (event) { deleteUnit(); });

        $('#CreateTeststep').click(function (event) { loadDialog(this, event, createTeststep); });
        $('#DeleteTeststep').click(function (event) { deleteTeststep(); });

        $('#SaveTemplate').click(function (event) { saveTemplate(); });    
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:28:01+00:00Added an answer on June 12, 2026 at 10:28 am

    I found your question rather confusing even after the update, so I still don’t really understand what you’re trying to do, but there seems to be two big problems with the way you’re using .data().

    The first problem is that you retrieve the value in a document ready handler:

    $(document).ready(function () {
        var templateId = $('#MyDialog').data('templateIdKey');
    

    …but the value isn’t stored until the loadDialog() function is called in response to a click so naturally there could be no data against that key at that time since no clicks have been processed yet.

    Secondly, you call the same loadDialog() function each time any of several elements is clicked, but each time loadDialog() is called it creates a new "MyDialog" div and then uses .data() to associate a key and value with that new div:

    var $dialog = $('<div id="MyDialog"></div>');
    // other code, then
    $dialog.load($contenturl).data('templateIdKey', templateIdValue)
    

    Again, your question isn’t clear but you seem to be saying that you expect this to update the value stored for the previously created "MyDialog" div but .data() associated values with individual elements. Why do you recreate the dialog div every time?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
English is not my native language. I need a software to spellcheck and correct
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
Why does the Android system throw this Exception? 05-18 12:33:44.169 W/System.err( 8230): java.io.IOException: Is
I want to open a popup window of an Image on More Info link
An Arabic name shall be sent via SOAP. The name is encoded like this:
I would like to run a str_replace or preg_replace which looks for certain words
I've successfully connected to XMPP server (from android XMPP client), and I can send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.