Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dynamically created object in javascript

Posted on 2016-08-18
5
Medium Priority
?
58 Views
Last Modified: 2016-09-02
how to add dynamically labels to a panel that contains a textbox but i need the label to be displayed before teh textbox
0
Comment
Question by:pamela rizk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41760682
Can you provide more information.

What do you mean by dynamic - what triggers the placement of the labels - what sort of labels are we talking about - can you describe in more detail?
0
 

Author Comment

by:pamela rizk
ID: 41760686
dear mr juian
it works using floar left
0
 
LVL 2

Expert Comment

by:Kyaw Wanna
ID: 41760768
Please try the codes as per below :
<html>
<head>
<title></title>

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<style type="text/css">
	div{
		padding:8px;
	}
</style>

</head>

<body>
 

<script type="text/javascript">

$(document).ready(function(){

    var counter = 1;

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

	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>
</head><body>

<div id='TextBoxesGroup'> 
</div>
<input type='button' value='Add Textbox' id='addButton'>
<input type='button' value='Remove Textbox' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>

</body>
</html>

Open in new window

0
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41760792
@Pamela, I still don't have a clear indication of what you want to achieve - can you draw us a picture.

You say the lable is added dynamically - what must happen for the lable to be added
Where do you get the text for the lable
Must the lable show all the time or only when you do something
0
 

Author Closing Comment

by:pamela rizk
ID: 41781166
f
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question