Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

joining fields into a variable 1

Status
Not open for further replies.

andybid

Vendor
Dec 7, 2010
23
0
0
GB
hi again

i am trying to create a date of birth from day,month,year variables. I cant get it working

Code:
<head>
<script type="text/javascript">
	function dobone() {
		var day = document.getElementById('day').value ;
		var mth = document.getElementById('month').value; 
		var year = document.getElementById('YY');
		var birth = day + "-" + mth + "-" + year;
		document.getElementById("dob").innerHTML = birth;
 
	return true}
		</script>
        </head>
        <body>
<p>Thank you.</p>
<p>&nbsp;</p>
<p>I need to take some personal details now ;</p>
<form id="form1" name="form1" method="POST" action="/site-test/personal.php?">
  <p>Title
    <input type="text" name="title" id="title" />
  </p>
  <p>firstname
    <input type="text" name="firstname" id="firstname" />
  </p>
  <p>lastname
    <input type="text" name="surname" id="surname" />
  </p>
  <p>date of birthday
    <select name="day" id="day">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
    </select>
    <select name="month" id="month">
      <option value="1" selected="selected">January</option>
      <option value="2">February</option>
      <option value="3">March</option>
      <option value="4">April</option>
      <option value="5">May</option>
      <option value="6">June</option>
      <option value="7">July</option>
      <option value="8">August</option>
      <option value="9">September</option>
      <option value="10">October</option>
      <option value="11">November</option>
      <option value="12">December</option>
    </select>
    <select name="YY" id="YY">
      <option value="99">1999</option>
    ....
      <option value="02">1902</option>
      <option value="01">1901</option>
      <option value="00" selected="selected">1900</option>
    </select>
  </p>
  <input type="text" id="dob" name="dob"  />
  <p>continue
    <input type="button" name="SubmitPers1" id="SubmitPers1" onClick="return dobone()" value="" />
  </p>
  <input type="hidden" name="MM_insert" value="form1" />
</form>

all i get is unknown runtime error in ie and month is null in firefox!

ta


<p>&nbsp;</p>

 
With a few changes, it works for me:

Code:
var year = document.getElementById('YY')[!].value[/!];
var birth = day + "-" + mth + "-" + year;
document.getElementById("dob")[!].value[/!] = birth;

Hope this helps,

Dan


Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Top - Cheers dan . Simple answers. love em.

I'l;l get the hang of this by the end !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top