473,698 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add Controls Dynamically in RoR?

16 New Member
The problem is, i have to add the controls dynamically in html/ruby html which should take the unique id for each controls.
Eg: If i click on add button say,control should create the code as follows..

Expand|Select|Wrap|Line Numbers
  1. <input type ="text" name="text1" id="text1">
  2.    <input type ="text" name="text2" id="text2">...
  3. How can i achieve this?Please help.Its urgent
  4.  
Thanks
Oct 29 '10 #1
1 2590
improvcornartist
303 Recognized Expert Contributor
You can use javascript to add new elements. Something like
Expand|Select|Wrap|Line Numbers
  1. function addElement() {
  2.   var div = document.getElementById('div1');
  3.   var element = document.createElement('input');
  4.   element.setAttribute('type', 'text');
  5.   element.setAttribute('name', 'text1');
  6.   element.setAttribute('id', 'text1');
  7.   div.appendChild(element);
  8. }
You will need to set the name and id dynamically, maybe by using a counter or something from your ruby code.
Nov 1 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1702
by: Punisher | last post by:
I'm adding checkbox controls to a table dynamically when the form loads for the first time. When a postback occurs, the controls are not maintained in the table. How do I get them to retain without having re-add them again.
2
1515
by: Mark Siffer | last post by:
I am trying to add a compare validator at runtime. I would add it before but my input controls are built at runtime via an editable datagrid. Therefore, the names of the controls are not known until the page has been rendered. Any ideas? Thanks in advance MS
3
2340
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
1
1398
by: Carol | last post by:
Hi, I am working in C# I have created one usercontrol. Now added a panel to this control. In a panel i have added another control. Now, i have added this usercontrol to a form. Now, on button click in this usercontrol i have to dynamically add the control to the same panel (panel already containing one control, the new control should be added below this control.)
0
1686
by: Przemek | last post by:
Hi, I'm trying to create menu dynamically (populated with dataset). I want to have it inside my div, which is inside another div and inside contentplaceholder. Unfortunately I'm receiving null reference expetions :/ Here is my aspx code: <asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server"> <div class="column">
6
1525
by: crazyjh | last post by:
hello i want to add some controls in according of the time. but when the time change, i call the method again to add controls again,No effect! i think maybe i should unload the controls adding before,how can i unload it?? pls help me,thanks
3
5487
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
2
359
by: Chris Botha | last post by:
I am adding controls dynamically to the page as per the samples there are on the Web and it works - I can create text boxes, buttons, my own user controls, whatever, on the fly and initialize them and add them to a placeholder no problem. However when I post back and the page displays again then all of the controls are gone. I create them when the IsPostBack is false, because the idea is to validate on post back, and if the data is invalid...
2
1202
by: laxmibokka | last post by:
adding controls dynamically In my asp.net application, i have to add dropdownlist(with yes/no options), and textbox to the table cells dynamically to each row of a table.The table also contains some other cells with data from database.The number of rows depends upon the backend data. And on selecting from the dropdownlist, the respective textbox should be enabled or disabled. If any one has an idea.Plz share with all of us. thanx in advance
1
1303
by: saadkhan | last post by:
Hello, I am working Visual Web Developer 2008, I`v learned alot of things including AJAX control toolkit. I want to dynamically add AJAX control AccordianPanes in an 'Accordian' on a buttons click event. I`v done it but its creating a new accordian on each click. Please help me out in it!
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.