tech99sri 04-30-2008, 01:30 PM Hi ,
I was trying to add a check box dynamically when a button is pressed.
The check box contains title and a textbox for the user to enter data.
For example , when the user hits addnew button , a new check box (title-name)
with a textbox for entering name should appear on the form.
Please help
thanks
abduraooft 04-30-2008, 01:33 PM The check box contains title and a textbox for the user to enter data.
Sorry, this is not clear, though you could find a lot examples for dynamic form by searching this forum, see
http://www.google.com/search?q=site%3Acodingforums.com+dynamic+form
tech99sri 05-01-2008, 06:15 AM Sorry, this is not clear, though you could find a lot examples for dynamic form by searching this forum, see
http://www.google.com/search?q=site%3Acodingforums.com+dynamic+form
there's a check box and a text box .
These should be visible when we click a button.
Please provide any example code .I am not able to find anything .
thanks
rangana 05-01-2008, 07:00 AM See if this basic example help :)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function Add()
{
var checkbox=document.createElement('input');
var inps=document.createElement('input');
var output=document.getElementById('output');
checkbox.type='checkbox';
inps.type='text';
inps.name='textboxname';
checkbox.name='checkname';
output.appendChild(checkbox);
output.appendChild(inps);
output.appendChild(document.createElement('br'));
}
</script>
</head>
<body>
<span id="output"></span>
<input type="button" value="Add" onclick="Add()">
</body>
</html>
tech99sri 05-01-2008, 04:28 PM Thankyou ,
I really appreciate your help .I was able to get the checkbox and the textbox when the click the add button.
How do I set the name (text infront of the textbox or the check box example firstname)
Sorry to ask a simple question ,I am new to java.
thanks
JoWiGo 05-01-2008, 05:09 PM First of all, you are using javascript, not Java. They are as different as apples and oranges. Microsoft ripped off Java's name when making javascript in hopes of increased popularity. Java is a desktop language, javascript is a web language.
Sorry, it's just something that bothers me.
Looks like if you are just trying to set the text between the two elements you can just use document.write. Just put it here...
...
output.appendChild(checkbox);
document.write("WHATEVER YOU WANT HERE!");
output.appendChild(inps);
output.appendChild(document.createElement('br'));
...
However you seem fairly new to coding in general, I really suggest picking up a book if you are going to be doing this for any length of time whatsoever, it will really help out in the long run.
tech99sri 05-02-2008, 12:48 AM hi,
I couldnot display the name of the check box and the text box
this is the code:
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%><div id="divform" style="position:absolute;z-index:2; ">
<form name="frm" id="frm" action="../wait.html" method="post" >
<div id="set1" style="position:absolute; left:65px;top:146px;" style = "hidden">
<span id="output"></span>
<input type="button" value="Add" onclick="Add()">
<script type="text/javascript">
function Add()
{
var inps=document.createElement('input');
var inpstext=document.createElement('input');
var value=document.createElement('input');
document.write("WHATEVER YOU WANT HERE!");
inps.type='checkbox';
inps.name='checkname';
document.getElementById('output').appendChild(inps);
document.getElementById('output').appendChild(inpstext);
}
</script>
</div>
</form>
When I press the add button just the text is displayed but the check box or the text filed is not displayed (they work fine without the document.write("WHATEVER YOU WANT HERE!");)
I will have to read some books in java script after this task is done , cos I dont have much time.
thanks
mjlorbet 05-02-2008, 01:17 AM First of all, you are using javascript, not Java. They are as different as apples and oranges. Microsoft ripped off Java's name when making javascript in hopes of increased popularity. Java is a desktop language, javascript is a web language.
sorry, this is not correct, javascript was developed by netscape. the rip-off you are trying to refer to is J#, microsoft's proprietary take on the java language for better integration into windows.
http://faculty.frostburg.edu/cosc/htracy/cosc120/MODULES120/NetPL/PL_Net.htm
rangana 05-02-2008, 01:23 AM Thankyou ,
I really appreciate your help .I was able to get the checkbox and the textbox when the click the add button.
How do I set the name (text infront of the textbox or the check box example firstname)
Sorry to ask a simple question ,I am new to java.
thanks
This should do it for you:
<form name="frm" id="frm" action="../wait.html" method="post" >
<div id="set1" style="position:absolute; left:65px;top:146px;" style = "hidden">
<span id="output"></span>
<input type="button" value="Add" onclick="Add()">
<script type="text/javascript">
function Add()
{
var checkbox=document.createElement('input');
var inps=document.createElement('input');
var label=document.createElement('label');
var output=document.getElementById('output');
checkbox.type='checkbox';
label.innerHTML='Firstname';
label.style.paddingRight='10px';
inps.type='text';
inps.name='textboxname';
checkbox.name='checkname';
output.appendChild(checkbox);
output.appendChild(label);
output.appendChild(inps);
output.appendChild(document.createElement('br'));
}
</script>
</div>
</form>
tech99sri 05-02-2008, 04:27 PM Hi ,
I am really very thankful for all your help.
How do I access the data in the textbox in to a collection object.
Please provide a solution
thanks
rangana 05-03-2008, 01:31 AM My apologies, but I can't understand it.
...What do you mean by collection object?..are you referring to an array?..
...Could you explain a little bit further :)
|
|