Results 1 to 2 of 2

Thread: Form Data help

  1. #1
    Join Date
    Jun 2008
    Posts
    22
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Default Form Data help

    Code:
     <script type="text/javascript">
      window.onload=function()
      {
    	  var df=document.forms;
    		  df[0].onsubmit=function()
    			  {
    			  var view=document.getElementById('contact_right').getElementsByTagName('label'),
    			  name=document.getElementById('contact_left').getElementsById('form_name')
    			  address=document.getElementById('contact_left').getElementsById('form_address')
    			  city=document.getElementById('contact_left').getElementsById('form_city')
    			  for(var i=0;i<view.length;i++)
    				  {
    				  view[i].firstChild.nodeValue=name[i].value;
    				  }
    			  return false; // This will disable the purpose of your submit.
    			  }
      }
     </script>
    Code:
       <div id="contact_left">
        <h2>Contact Information</h2>
        <form action="#" method="#">
         <label for="name">Name:</label>
         <input class="input" type="text" id="form_name">
    	 <br />
         <label for="address">Address:</label>
         <input class="input" type="text" id="form_address">
    	 <br />
         <label for="city">City:</label>
         <select class="select" id="form_city">
          <option value="1">Beaverton</option>
          <option value="2">Hillsboro</option>
          <option value="3">Portland</option>
          <option value="4">Tannasbourne</option>
          <option value="5">Tigard</option>
          <option value="6">Vancouver</option> 
         </select>
    	 <br />
         <input class="submit" type="submit" value="Submit">
        </form>
       </div>
       <div id="contact_right">
        <h2>Your Information</h2>
    	<form action="#" method="#">
    	 Name: <label>Name</label><br>
    	 Address: <label>Address</label><br>
    	 City: <label>City</label><br>
    	</form>
       </div>
    Ok, so I am just trying to take form data and display it in another div sitting right next to it. I broke each field down into different variables in the script because I don't know if I could take the data from the select box field. I assume at this point, it is actually grabbing each value??? How would I go about getting that to display? At this point, it doesn't, big suprise. lol

    On top of that, how do I take that value that will eventually be retrieved by the javascript for the select box and turn it back into that "option name" when it is outputted in the other contact_right div?

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    This was the script i've given to you. Apologies, if it is giving you much trouble.

    First, ID is unique, So this part is erroneous:
    Code:
    name=document.getElementById('contact_left').getElementsById('form_name')
    See if this script helps:
    Code:
    <script type="text/javascript">
      window.onload=function()
      {
    	  var df=document.forms;
    		  df[0].onsubmit=function()
    			  {
    			  var view=document.getElementById('contact_right').getElementsByTagName('label'),
    			  inps=document.getElementById('contact_left').getElementsByTagName('input'),
    			  city=document.getElementById('form_city');
    			  for(var i=0;i<inps.length-1;i++)
    				{
    				var rang=inps[i].value;
    				view[i].firstChild.nodeValue=rang;
    				view[2].firstChild.nodeValue=city.value;
    				}
    			  return false; // This will disable the purpose of your submit.
    			  }
      }
     </script>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •