SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: 2 forms

Hybrid View

  1. #1
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 forms

    Hello,

    I have two forms in my html page. How may I know of a variable value which is in the first form and use it's value in second form.

    Pls let me know of any help.
    -1/2=999?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you try document.forms[number]

  3. #3
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried document.getElementById(x), it works to some extent. I mean I could write the value of a text field into another but can not pass it via the form, who needs the enc-type for file uploading, to server environment.

    No, I never tried document.forms[number], could you please show me an example. Thanks for your help.
    -1/2=999?

  4. #4
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I should correct a fault. If what you mean is document.form1["description"].value for example, Yes that's for sure I have used it alot before, but I think it won't be a help to me as what I want is to send the value of a variable in form1 to form2.

    Form2 is being submitted not form1. Form2 has the encode-type as I already mentioned.

    Please let me know weather I could express my problem clearly or not.
    -1/2=999?

  5. #5
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onBlur

    I was able to send the value of the text-box using a simple function sensetive in onBlur(). Is there any other way?
    -1/2=999?

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the following code helps you?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>JavaScript Test :: </title>
    <script language="javascript">
    function TransferValues(current_form){
    	document.forms[1].txtName.value = current_form.txtName.value;
    	document.forms[1].txtAddress.value = current_form.txtAddress.value;
    }
    </script>
    </head>
    <body>
    <table width="405" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
    	<form name="firstForm" method="post" action="">
    	<table width="400" border="0" cellspacing="0" cellpadding="2" style="border:1px #CCCCCC inset;">
          <tr>
            <td height="22" colspan="3" style="background-color:#CCCCCC;font-weight:bold;">First Form </td>
          </tr>
          <tr>
            <td width="91" height="22">NAME</td>
            <td width="231"><input name="txtName" type="text" id="txtName" onBlur="TransferValues(this.form);"></td>
            <td width="76">&nbsp;</td>
          </tr>
          <tr>
            <td height="22">ADDRESS</td>
            <td><input name="txtAddress" type="text" id="txtAddress" onBlur="TransferValues(this.form);"></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="22">&nbsp;</td>
            <td><input type="submit" name="Submit" value="Submit"></td>
            <td>&nbsp;</td>
          </tr>
        </table>
    	</form>
    	</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>
    	<form name="secondForm" method="post" action="">
    	<table width="400" border="0" cellspacing="0" cellpadding="2" style="border:1px #CCCCCC inset;">
          <tr>
            <td height="22" colspan="3" style="background-color:#CCCCCC;font-weight:bold;">Second Form </td>
          </tr>
          <tr>
            <td width="91" height="22">NAME</td>
            <td width="231"><input name="txtName" type="text" id="txtName"></td>
            <td width="76">&nbsp;</td>
          </tr>
          <tr>
            <td height="22">ADDRESS</td>
            <td><input name="txtAddress" type="text" id="txtAddress"></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="22">&nbsp;</td>
            <td><input type="submit" name="Submit2" value="Submit"></td>
            <td>&nbsp;</td>
          </tr>
        </table>
    	</form>
    	</td>
      </tr>
    </table>
    </body>
    </html>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  7. #7
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, Thanks so much! The way I followed is really using such ideas;
    Code:
    function saveHeader(y) {
      	var subject=document.getElementById('subject').value!="" ? document.getElementById('subject').value : "n\\a";					
    	var to=document.getElementById('to').value!="" ? document.getElementById('to').value : "n\\a";					
    	var frameId=document.getElementById('iframe'+y);	
     	frameId.src="mailHandler?actionType=recordMailHeader&subject="+subject+"&to="+to;	
    	alert("subject: "+subject+" , To: "+to);
        }
    where the function is called by onBlur appropriately.
    -1/2=999?


Bookmarks

Posting Permissions

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