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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:38:00+00:00 2026-06-08T09:38:00+00:00

on my MVC3 razor page,I am trying to dynamically add a textbox with click

  • 0

on my MVC3 razor page,I am trying to dynamically add a textbox with click of a button

Pasted below is my Jquery .But when I click addButton ,I am getting the above error message .

To resolve this error I tried adding <script type="text/javascript" src="jquery-1.3.2.min.js"></script> ,but still I am getting the same error .Appreciate your suggestions to resolve this error.

<script type="text/javascript">



    $(document).ready(function(){



        var counter = 2;



        $("#addButton").click(function () {



            if(counter>10){

                alert("Only 10 textboxes allow");

                return false;

            }   



            var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);

                newTextBoxDiv.after().html('<label>Textbox #'+ counter + ' : </label>' +

                '<input type="text" name="textbox' + counter + 

                '" id="textbox' + counter + '" value="" >');



            newTextBoxDiv.appendTo("#TextBoxesGroup");



            counter++;

        });



        $("#removeButton").click(function () {

            if(counter==1){

                alert("No more textbox to remove");

                return false;

            }   

            counter--;



            $("#TextBoxDiv" + counter).remove();

        });



        $("#getButtonValue").click(function () {



            var msg = '';

            for(i=1; i<counter; i++){

                msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();

            }

            alert(msg);

        });



  });

</script>

enter image description here

  • 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-08T09:38:02+00:00Added an answer on June 8, 2026 at 9:38 am

    you may want to use jquery all the way instead of mixing up native DOM and jquery. this one will actually work:

    var newTextBoxDiv = $('<div id="TextBoxDiv' + counter + '"><label>Textbox #'+ counter + ' : </label><input type="text" name="textbox' + counter + '" id="textbox' + counter + '" value="" ></div>'); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With ASP.NET MVC3 (Razor) I have a simple page that loads a jQuery UI
I'm using jQuery Validate Unobtrusive with ASP.NET MVC3 Razor. I have a page with
I'm working on an MVC3 Razor web application which gets it's page decoration from
New to MVC3 Razor - linq to sql having spent some time trying to
I am using jquery modal popup in my application with MVC3 Razor view. Issue
I need to use a static html page as an MVC3 razor masterpage. It
I'm trying to learn ASP.NET MVC 3 with razor and so far getting the
I'm using jquerymobile and asp.net MVC3 razor. I'm somewhat new to this, but figuring
I'm trying to convert a small mvc2 application to the mvc3 razor syntax. In
Context: Asp.Net MVC3 w/Razor I am trying to put a login form on a

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.