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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joing form data and passing onto another page?

Status
Not open for further replies.

Atchett

Programmer
Dec 7, 2000
35
Hi all,

I am trying to collect a date of birth from a form and then enter it into a database.

The problem that I am having is...

The 3 parts of the dob are in seperate drop down lists (not my favorite but it's not my choice!). I need to join the seperate parts together and then enter this into the db via another page. I am using this function to join the parts (which seems to work) :-

function getDateOfBirth()
{
DateOfBirthArr = new Array()
DateOfBirthArr[0] = dob_d.value;
DateOfBirthArr[1] = dob_m.value;
DateOfBirthArr[2] = dob_y.value;

DateOfBirth = DateOfBirthArr.join("-");
}

but I cannot seem to get the resulting dob to pass through to the next page.

I have tried <input type=&quot;hidden&quot; value=&quot;javascript:getDateOfBirth()&quot; name=&quot;DateOfBirth&quot;>

but it just comes through with javascript:getDateOfBirth() on the next page?

Does anyone have any ideas?

Many thanks in advance.
 
Here is a simple function to give you the idea of query strings - which are the only way to send info - other than cookies or cumbersome frames. Basically you write the query part from form data - and add it to the URL for the next page. This function could be called from a button clicked after completion of the details.

Query string | General syntax:
...href=&quot;pageName.htm?var1=something&var2=somethingElse&quot;
start of query indicated by &quot;?&quot; - everything else is for easy manipulation at the other end

<script>
function send(form){
var string =&quot;?name=&quot; + form.name.value +&quot;&dob=&quot; + form.dob.value;
document.location=&quot;target.htm&quot; + string;
}
</script>


When the target page is loaded, the infromation is stored at location.search. From here you use methods belonging to String objects to split it up and use the info.
Quite often I will split at the &quot;&&quot; sign, thenjust execute the pieces using eval() - which would set variables called name and dob in this case.
I think there is a FAQ on this in the JavaScript forum.
b2 - benbiddington@surf4nix.com
 
Or you could try this,

have this as your JScript
function getDateOfBirth()
{
    DateOfBirthArr = new Array()
    DateOfBirthArr[0] = dob_d.value;
    DateOfBirthArr[1] = dob_m.value;
    DateOfBirthArr[2] = dob_y.value;
    document.dobentry.DateOfBirth.value = DateOfBirthArr.join(&quot;-&quot;);
document.dobentry.submit()

}

the first red line passs the information into the following form and the second line activates the form and moves to the next page.

<form method = post name=dobentry action=nextpage.html>
<input type=hidden name=dob value=''>
<a href=javascript:getdateofbirth()><input type=button value=Submit></a>
</form>

Then when you get to the second &quot;nextpage.html&quot; you will need to do a request(&quot;dobentry&quot;) to get the transferred data.

Hope that helps as well. DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 

function getDateOfBirth()
{
    DateOfBirthArr = new Array()
    DateOfBirthArr[0] = dob_d.value;
    DateOfBirthArr[1] = dob_m.value;
    DateOfBirthArr[2] = dob_y.value;
    document.dobentry.dob.value = DateOfBirthArr.join(&quot;-&quot;);
document.dobentry.submit()
}

sorry noticed a fault as soon as i posted, the above highlighted change should be made to avoid an error. DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Many thanks to you both. All sorted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top