Click to See Complete Forum and Search --> : generating textboxes at runtime
srimca
01-23-2003, 10:41 PM
hi freinds..
i am creating a web page for registration.
if the user selects a category employee then an textbox should be displayed in the same page.this should be done at runtime.if the user selects vendor then he should be directed to a new page.how to do this using java script.
remember this should happen at runtime/
thanx
khalidali63
01-23-2003, 11:05 PM
The most appropriate way dojng this will be using DOM to re arrange code.
take a look at the example below.
<script type="text/javascript">
function addElement(){
var frm = document.getElementById("form1");
var el = document.createElement("input");
el.setAttribute("type","text");
frm.appendChild(el);
}
</script>
</head>
<body onLoad="presDocs03TotPgs();">
<form id="form1">
<input type="button" onclick="addElement();" value="add element"></input>
</form>
Take a look at the DOM spcs at w3c.org
for detailed docs.
Cheers
Khalid
srimca
01-23-2003, 11:10 PM
hello dave
u didnt get my question!!
now i have a web page consisting of a combo box called usercategory- 1)employee2)vendor.
when the user selects employee a textbox should be displayed below it dynamically(runtime).
if the user selects vendor then a new page should be displyed.
how to do thsi using javascript
bye
khalidali63
01-23-2003, 11:21 PM
I guess this should do it for you.
Khalid
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5"></meta>
<meta name="Author" content="Khalid Ali"></meta>
<title>Untitled</title>
<script type="text/javascript">
function process(){
var frm = document.form1;
var listBox = frm.usercategory;
var index = listBox.selectedIndex;
var value = listBox[index].value;
if(value=="empl"){
addElement();
}else if(value=="vend"){
loadURL("http://www.netscape.net");
}
}
function loadURL(url){
window.location.href = url;
}
function addElement(){
var frm = document.getElementById("form1");
var el = document.createElement("input");
el.setAttribute("type","text");
frm.appendChild(el);
}
</script>
</head>
<body>
<form id="form1" name="form1">
<select name="usercategory" onchange="process();" style="width:100pt;">
<option value="-1">List box </option>
<option value="empl">Employee</option>
<option value="vend">Vendor</option>
</select>
</form>
</body>
</html>
srimca
01-23-2003, 11:24 PM
thanx khalid..
that was gr8
i want a combo box.
now when i select an option ,the textbox should eb displayed.
pls explain ur code.
what is getelementbyid.
why have u given createelement ("input") when i want a text box.i feel inputbox is different from textbox.
khalidali63
01-23-2003, 11:45 PM
what is what is getelementbyid
geteLementById()
is a DOM specific method to reference any part of the HTML tags.(there may be some exceptions,such as iframe, that can not be referenced like this).
why have u given createelement ("input") when i want a text box.i feel inputbox is different from textbox.
document.createElement("input") (another dom method),creates a new html element
<input
then I set an attribute for this element type = "text"
the above creates the following in memory.
<input type="Text">
In HTML there is input type text you can call it text field,textbox or whatever you may likeand there is another text related field called textarea.
Take alook at DOM tutorials on
w3c.org
cheers
Khalid
khalidali63
01-24-2003, 08:34 AM
God..lighten up already......
I thought we all here are mature and grown ups,and if some one disagrees or dislikes our solutions we do not spit fire,
apparently either I was wrong or we have people who can not take disagreement lightly.
This forum here is for help,if some one can provide that,good, otherwise they should rest there piece instead of starting fire.
cheers
Khalid
khalidali63
01-24-2003, 09:21 PM
I guess you are right,its frigging above -30 in here.
peace ..
cheers
Khalid