Passin text from form to form with JS

Sharky Forums


Results 1 to 3 of 3

Thread: Passin text from form to form with JS

  1. #1
    Expensive Sushi
    Join Date
    May 2001
    Location
    Surrey, BC, Canada
    Posts
    35

    Passin text from form to form with JS

    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

  2. #2
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    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:

    Code:
    <html><head> 
    	<script language="JavaScript"> 
    		function TransferVal() { document.formName2.Name2.value=document.formName1.Name1.value; } 
    	</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.

  3. #3
    Expensive Sushi
    Join Date
    May 2001
    Location
    Surrey, BC, Canada
    Posts
    35
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •