By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

Replicate textbox value

P: n/a
Hi.

I have a form with some textboxes in it. When a user clicks a button,
I need to verify if only one of the textboxes if filled and if so, I
need to replicate the value of this textbox to all other textboxes on
the form. If two or more textboxes are filled I don't need to do the
replication. How can I do that?

Thanks,

Robert Scheer
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Here is sample code to do that:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function checkForm1(callerValue){
if (howManyFilled() == 1)
fillAll(callerValue)
}

function fillAll(value){
for (var i=0; i < document.forms['form1'].elements.length; i++){
document.forms['form1'].elements[i].value = value;
}
}

function howManyFilled(){
var howmany = 0;
for (var i=0; i < document.forms['form1'].elements.length; i++){
if (document.forms['form1'].elements[i].value == "")
continue
howmany++
}
return (howmany);
}
//-->
</script>
</head>

<body>
<form name="form1">
<input type="text" name="textbox1" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox2" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox3" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox4" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox5" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox6" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox7" onchange="checkForm1(this.value)"><br>
<input type="text" name="textbox8" onchange="checkForm1(this.value)"><br>
</form>
</body>
</html>

"Robert Scheer" <rb******@my-deja.com> wrote in message
news:cf**************************@posting.google.c om...
Hi.

I have a form with some textboxes in it. When a user clicks a button,
I need to verify if only one of the textboxes if filled and if so, I
need to replicate the value of this textbox to all other textboxes on
the form. If two or more textboxes are filled I don't need to do the
replication. How can I do that?

Thanks,

Robert Scheer

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.