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 6737381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:14:32+00:00 2026-05-26T11:14:32+00:00

I have an ASP.NET MVC3 application, and I have the task to insert some

  • 0

I have an ASP.NET MVC3 application, and I have the task to insert some HTML code (some form) and Javascript code (mostly jQuery validation for the inserted form) into the DOM of a web page – the HTML and the Javascript code are both returned via Ajax calls:

         var id = jQuery(this).attr("data-id");
         var querystring = "id=" + id;
         jQuery.ajax({
             type: "GET",
             url: "Home/GetEditViewHTMLById",
             data: querystring,
             dataType: "html"
         }).done(function (msg_html) {
             jQuery.ajax({
                 type: "GET",
                 url: "Home/GetEditViewJavascriptById",
                 data: querystring,
                 dataType: "script"
             }).done(function (msg_javascript) {
                 jQuery("#content").html(msg_html); // inserting the HTML

                 var script = document.createElement("script");
                 script.type = "text/javascript";
                 script.text = msg_javascript;
                 document.body.appendChild(script); // inserting the Javascript - doesn't work
                 Edit(); // <- this function would be in the inserted Javascript code
             });
         });

The “msg_javascript” variable contains the Javascript code, if I call alert, I can see the result of the Ajax call:

       function Edit(){
          jQuery("#plugin").validate( { errorElement: 'div' } );
          jQuery("#sum1").rules("add", { required: true, messages: { required: "!" }  });
          jQuery.validator.addMethod("regex_sum1",
                  function (value, element, regexp) {
                      var check = false;
                      var re = new RegExp(regexp);
                      return re.test(value);
                  },
                  "Wrong number format!");
          jQuery("#sum1").rules("add", { regex_sum1: "^[1-9][0-9]*$" });
          jQuery("#sum2").rules("add", { required: true, messages: { required: "!" }  });
          jQuery.validator.addMethod("regex_sum2",
                  function (value, element, regexp) {
                      var check = false;
                      var re = new RegExp(regexp);
                      return re.test(value);
                  },
                  "Wrong number format!");

          jQuery("#email").rules("add", { required: true, messages: { required: "!" }  });

          jQuery.validator.addMethod("regex_email",
                  function (value, element, regexp) {
                      var check = false;
                      var re = new RegExp(regexp);
                      return re.test(value);
                  },
                  "Wrong e-mail format!");
          jQuery("#email").rules("add", { regex_email: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$" });
          jQuery('input').blur(function(){
                          if(!jQuery(this).valid()){
                             return false;
                         }
                      });

          function calculate(){
               return (Number(jQuery('#sum1').val())*(Number(jQuery('#sum2').val())+0.5));
          }
          function getFields(){
               return ["sum1","sum2"];
          }
          function validateRange(value){
               return 1000 <= value && value <= 10000;
          }}

If I return the following function from server:

          function Edit(){ 
                alert("okay");
          }
  • everything is okay, and the alert executes.
    If I return that Javascript function above, the function doesn’t execute, and I can’t see the script tag in the Firebug neither, so I don’t really know how to debug this problem.
    What did I do wrong? Please, any help is appreciated.
  • 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-05-26T11:14:32+00:00Added an answer on May 26, 2026 at 11:14 am

    Javascript doesn’t run in a returned variable, you must execute it:

    eval(msg_javascript);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC3 web application with C# and Razor. Through a form
I have following code in my asp.net MVC3 application: string msg = Beginning report
I have asp.net form that contains fields. When I access this window, my javascript
I have ASP.Net code generating my button's HTML for me using divs to get
I have ASP.NET MVC application that has list with jQuery Selectable list. My problem
I'm making an ASP.Net MVC 3 application in VS 2010. I have a task
My application is in Asp.Net MVC3 coded in C#.Net. I have Views which contains
I have online form builder appplication in ASP.NET MVC3 with Razor views. It is
I have an ASP.NET MVC3 application in which I am creating multiple areas, is
Here's the issue at hand: I have developed an ASP.NET MVC3 application using Razor.

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.