Click to See Complete Forum and Search --> : checkbox & textfields ,,,help!!!!!


s.vidya
10-12-2003, 06:59 AM
hi guys,,,

I need help in javascript ,,the problem is that i need the checked values of any of the checkboxes to go to the textfields randomly

meaning,,if i check the 4rth checkbox ,,its value should go to the first textfield ,,and similiarly if i suppose ,,check the 7th check box ,,its value should go to the 2nd textfield and ,,,

I hope someone helps me,,bec the time is coming to a deadline
:confused:

Khalid Ali
10-12-2003, 09:23 AM
do the following.

name all the text fields in the form element same such as
name="tfields"
now having the same name for all text fields will create an array of text fields.

then get the totoal number of text fields using

var len = document.formName.tfields.length;

now get the reandom number thats less then or equal to the len

var index = Math.random() * len;

njoy
and now access the fields
document.formName.tfields[index].value = "value"

s.vidya
10-13-2003, 03:27 AM
Originally posted by Khalid Ali
do the following.

name all the text fields in the form element same such as
name="tfields"
now having the same name for all text fields will create an array of text fields.

then get the totoal number of text fields using

var len = document.formName.tfields.length;

now get the reandom number thats less then or equal to the len

var index = Math.random() * len;

njoy
and now access the fields
document.formName.tfields[index].value = "value"


what u have told me does not help me in my problem..,,
I will tell you the details of my problem,,


There is one page containning textfields and a submit button,When i click the submit button ,a new page opens containning checkboxes, with corresponding textfields and submit button,.Now when i check the boxes on the second page, and click the submit button ,the values of the corresponding textfields ,go to the corresponding textfields in the first page,, meaning

that if i check the 3rd checkbox in the second page, the value of the textfield corresponding to the 3rd checkbox in the second page goes to the third textfield in the first page ,,and similarly ,if i check the 5th checbox,the corresponding textfield value in the second page,goes to the 5th textfield in the first page,,and hence skipping the textfields,,which i dont want to happen

I want the values from the randomly checked boxes textfield in the second page,to go the first pages textfields in a sequence ,starting from the first textfield and then second ,,third ,,,,,,in the first page

I hope you understood what i have told

cheers

vidya

lillu
10-13-2003, 07:52 AM
Do you mean this?

<html>
<head></head>
<body>
<form name="form1">
1<input type="checkbox" value="1" onClick="document.form2.field1.value=this.value">
2<input type="checkbox" value="2" onClick="document.form2.field2.value=this.value">
</form>
<form name="form2">
<input type="text" name="field1">
<input type="text" name="field2">
</form>
</body>
</html>

If so, you can populate the textboxes using a for loop that goes through the checkboxes and copies the values only of the checked checkboxes.

s.vidya
10-13-2003, 11:21 PM
Originally posted by lillu
Do you mean this?

<html>
<head></head>
<body>
<form name="form1">
1<input type="checkbox" value="1" onClick="document.form2.field1.value=this.value">
2<input type="checkbox" value="2" onClick="document.form2.field2.value=this.value">
</form>
<form name="form2">
<input type="text" name="field1">
<input type="text" name="field2">
</form>
</body>
</html>

If so, you can populate the textboxes using a for loop that

goes through the checkboxes and copies the values only of the checked checkboxes.

okay,,,let me get it this way,,

There is one page having textfields and there is an another page having checkboxes,
Now when i check the checkboxes randomly,i want the values of the checkboxes to go to the textfields in a sequence,starting from the first textfield

lillu
10-14-2003, 08:57 AM
Ok, here's an example I doodled with.

<HTML>
<HEAD>
<TITLE>Untitled Document</TITLE>
<script language="javascript">
function addValue()
{
var str = ""
for (i=0; i<document.form1.check.length; i++)
if (document.form1.check[i].checked)
document.form2.text[i].innerText = document.form1.check[i].value;
else
document.form2.text[i].innerText = "";
}
</script>
</HEAD>
<BODY>
<FORM name="form1" method="post" action="">
<INPUT type="checkbox" name="check" value="0">
<INPUT type="checkbox" name="check" value="1">
<INPUT type="checkbox" name="check" value="2">
<INPUT type="checkbox" name="check" value="3">
</FORM>
<form name="form2">
<input type="text" name="text">
<input type="text" name="text">
<input type="text" name="text">
<input type="text" name="text">
</form>
<INPUT type="button" value="Show" onclick="addValue()">
</BODY>
</HTML>