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

Filling in a form with a hyperlink 1

Status
Not open for further replies.

emozley

Technical User
Joined
Jan 14, 2003
Messages
769
Location
GB
Hi,

Is it possible to fill in two form fields with a hyperlink and without reloading the page?

I have one box called StartDate and one called EndDate - I have a hyperlink which says 'Last 7 days' - I can use ASP to get a value for today's date and the date 7 days ago and embed those values in the hyperlink just not sure how to pass them to the form.

Thanks very much

Ed
 
Sure you can. Here is an example using a button and using an href link:
Code:
<form name="myForm" action="">
<input name="start" type="text">
<input name="end" type="text">
<!-- using a button -->
<input type="button" onclick="setStartEndDates('13/5/2005','20/5/2005');" value="Set dates">
<!-- using a href -->
<a href="javascript:setStartEndDates('13/5/2005','20/5/2005');>Set dates</a>
</form>
...
<script type="text/javascript">
function setStartEndDates(_start, _end) {
  var f = document.forms['myForm'];
  if (_start != '') f.elements['start'].value = _start;
  if (_end!= '') f.elements['end'].value = _end;
}
</script>
Hope this gets you going!

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Absolutely perfect - thanks very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top