Click to See Complete Forum and Search --> : Passin text from form to form with JS


Triple__J
04-08-2002, 06:19 PM
Hi I have two examples the first is how I did it with select box

<html>
<head>
<script language="JavaScript"><!--
function setForm2Value() {
var selectedItem = document.formName1.selectName1.selectedIndex;
var selectedItemValue = document.formName1.selectName1.options[selectedItem].value;
var selectedItemText = document.formName1.selectName1.options[selectedItem].text;

if (selectedItem != 0) {
document.formName2.textboxName1.value = selectedItemText;
document.formName2.textboxName2.value = selectedItemValue;
}
else {
document.formName2.textboxName1.value = "";
document.formName2.textboxName2.value = "";
}
}
//--></script>
</head>
<body>
<form name="formName1">
<select name="selectName1" onChange="setForm2Value()">
<option>Select one:
<option value="Intelligent">Doc
<option value="cheerful">Happy
<option value="miserable">Grumpy
<option value="wide awake">Sleepy
<option value="smart">Dopey
<option value="shy">Bashful
<option value="breathing">Sneezy
</select>
</form>

<p>

<form name="formName2">
<input type="textbox" name="textboxName1" value="" size="10">
is
<input type="textbox" name="textboxName2" value="" size="10">
</form>

</body>
</html>

the Second is with text box

<html>
<head>
<script language="JavaScript">
function setForm2Value() {
var ItemName = document.formName1.Name.text;
var ItemText = document.formName1.Text.text1;

if (selectedItem != 0) {
document.formName2.Text.value = text;
document.formName2.Text1.value = text;
}
else {
document.formName2.Text.value = "";
document.formName2.Text1.value = "";
}
}
</script>
</head>
<body>

<form name="formName1" onChange="setForm2Value()">


Name:&nbsp;<input type="text"name="Name" size=25><br>
New comment:&nbsp;&nbsp;<textarea rows="10" name="Text" cols="50"></textarea><br><br>
<input type="submit"name="submit" value="Submit">&nbsp;<input type="reset" name="reset" value="Reset"><br><br>
</form>
<form name="formName2">
Name:&nbsp;<input type="textbox" name="Text" value="" size="10"><br>
Comments: <textarea rows="10" name="Text1" cols="91"></textarea><br><br>


</form>
</body>
</html>

the Question is can I or can I not pass the info in text box on formName1 to formName2 .
Not to sure how to do this. Any idea would be good thanks

Grizzly
04-08-2002, 11:05 PM
I'm not 100% sure I follow your question, but my impression is you're confused on how to pass a text box's value off to another text box. Here's a quick & simple example:


<html><head>
<script language="JavaScript">
function TransferVal() { document.formName2.Name2.value=document.formName1.Name1.valu e; }
</script>
</head><body>
<form name="formName1">
Name:
<input type="text"name="Name1" size=25>
<input type="button" value="Pass it on..." onClick="TransferVal()"><br><br>
</form>
<form name="formName2">
Result:
<input type="text"name="Name2" size=25>
</form>
</body></html>


G'luck buddy.

Triple__J
04-09-2002, 09:55 AM
thanks that's closer then I was I still have to do a little but that get's me on the right path thank you :)