PDA

View Full Version : Unable to create box with button click ...using Javascript



manashi_130582
03-28-2006, 07:08 AM
hi
i hav created 3 buttons
MORE - is should generate a text box and combo box everytime it is clicked
FEWER-is should delete a text box and combo box everytime it is clicked
SHORTLIST- it should display the resul into anothe page

I hav used JAVASCRIPT...

The code is as follows :-


function addRow(frmCriteria)
{
var tmp = frmCriteria.sub_cnt.value;
tmp++;
frmCriteria.sub_cnt.value = tmp;
frmCriteria.action = "shortlist_by_cutoff.php?group="+frmCriteria.grp_id.value;
}

function removeRow(frmCriteria)
{
if( frmCriteria.sub_cnt.value > 1)
{
var tmp = frmCriteria.sub_cnt.value;
tmp--;
frmCriteria.sub_cnt.value = tmp;
frmCriteria.action = "shortlist_by_cutoff.php?group="+frmCriteria.grp_id.value;
}
else
{
return false;

}
}

the code inside form tag :-


<form name="criteria_frm" action="shortlist_cutoff_act.php?group=$group" method="POST">

<input type="hidden" name="grp_id" value="<?php echo $group;?>">

**<input type="hidden" name="sub_cnt" value= ??> //it takes the value of tmp(javascripts) but i dnt knw how to sho the value

<input type="submit" onclick="return addRow(document.criteria_frm)" value="More">
<input type="submit" onclick="return removeRow(document.criteria_frm)" value="Fewer">

<input type="submit" value="Shortlist" onclick="return DoSubmit(document.criteria_frm)">

when i am executin is not giving desired result... :confused: :(
waitin for the reply.... :)

djr33
03-28-2006, 07:11 AM
Wanna link us to the page where this is in action? That'll be helpful in addition to the code.

manashi_130582
03-28-2006, 08:38 AM
sorry i did not get ur answer...

.alias.
03-28-2006, 02:48 PM
He means post a link to YOUR website so we can see what is happening on it

manashi_130582
03-29-2006, 06:01 AM
i dnt hav link... i am running it on localhost + its a part of my project that i am currently doing that deals with online candidate evaluation system...
i hav got the solution for the problem...
bt my new doubt is ..
a hav a combobox that contains the name of the subjects...
bt when i am clicking the MORE button the combo box is gettin created by data is not there in it...
the code is as follows :-
<script type="text/javascript">

function insRow()
{
var x=document.getElementById('mytab').insertRow(0)
var y=x.insertCell(0)
var z=x.insertCell(1)
var txt1=document.createElement("input");
var txt2=document.createElement("select");
txt1.size="5";
y.appendChild(txt1);
z.appendChild(txt2);
}
</script>


the code inside form tag is :-


<form name="chg" action="9.php" method="POST">
<table cellspacing=2 cellpadding=2 border=1>
<tr><th>col1</th></tr>
<tr><td>
<table>
<tr>
<th>head1</th>
<th>head2</th>
</tr>
</table>
</td></tr>
<tr><td>
<table id="mytab">
<tr><td><input type="text" size=5 name="nam1"></td>
<td><select name="nam2" id="sel">
<option>java</option>
<option>C++</option>
<option>DS</option> </td>
</tr>
</table>
</td></tr>
<tr><td><input type="button" onclick="insRow()" name="but" value="ADD">
</td></tr>
</table>
</form>

how to rectify the error....
Here i hav specified the data in combobox but actually the data is taken from
Database using PHP tag... i am using postgreSQL as DB....
if the above code work in creating combobox with the specified data there will not be problem with data take from DB...
Waitin for the reply......

manashi_130582
03-29-2006, 06:17 AM
i dnt hav link + its the project that i am doing that deals with candidate evaluation system...

i hav got the solution for above mentioned problem..
but my new doubt is...
when i am clickin thr MORE button new combo box is gettin created but data is not there in it that was in 1st combo box...
the code is as follows :-

function insRow()
{
var x=document.getElementById('mytab').insertRow(0)
var y=x.insertCell(0)
var z=x.insertCell(1)
var txt1=document.createElement("input");
var txt2=document.createElement("select");
txt1.size="5";
y.appendChild(txt1);
z.appendChild(txt2);
}

the code inside the form tag is :-

<form name="chg" action="9.php" method="POST">
<table cellspacing=2 cellpadding=2 border=1>
<tr><th>col1</th></tr>
<tr><td>
<table>
<tr>
<th>head1</th>
<th>head2</th>
</tr>
</table>
</td></tr>
<tr><td>
<table id="mytab">
<tr><td><input type="text" size=5 name="nam1"></td>
<td><select name="nam2" id="sel">
<option>java</option>
<option>C++</option>
<option>DS</option> </td>
</tr>
</table>
</td></tr>
<tr><td><input type="button" onclick="insRow()" name="but" value="ADD">
</td></tr>
</table>
</form>


here i hav inserted the data in combobox but actually the data is taken from DB and its inserted in combobox by using PHP tag....
if the above code works then it will work for the DB code in PHP tag also...
Waiting 4 the reply.......:)

Suresh T.
06-14-2006, 06:46 PM
try this

function insRow()
{
var x=document.getElementById('mytab').insertRow(0)
var y=x.insertCell(0)
var z=x.insertCell(1)
var txt1=document.createElement("input");
var txt2=document.createElement("select");
var txt3=document.createElement("option");
txt1.size="5";
y.appendChild(txt1);
z.appendChild(txt2);
txt2.options.add(txt3);
txt3.innerText = "abc";
txt3.value = "abc1";
txt3.selected = "true";


}

Twey
06-14-2006, 07:16 PM
txt3.innerText = "abc";Not necessary and will error out in all but IE.