Solved

combine three separate date select fields into one post value?

Posted on 2014-02-21
6
715 Views
Last Modified: 2014-02-21
Hi Experts,

In my form generated with server based classic ASP we have date select with three separate select fields.

date select
Would it be possible with client based scripts to transform this into a single form value without changing the looks and behavior in the form?

All help is welcome as long as it does not transforms the looks.

Thanks
0
Comment
Question by:Steynsk
6 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39876604
The answer: There's a very good chance you can do this client side with jquery. You would need to supply a typical view source of a rendered page that has the form on it.

I'm not an expert in classic asp, but you could also do things like this server side quite easily in asp.net.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39876635
<%
' in asp
' assuming vars for day, month, year

day=1
month=2
year=2014
theDate=day&"/"&month&"/"&year
response.write theDate

%>
<input type="hidden" name="fulldate" value="<%=theDate%>">

Open in new window

0
 
LVL 22

Expert Comment

by:Om Prakash
ID: 39876687
Assuming you have placed a button and on click of button you want to combine these fields, try the following code:


assuming dropdown names are d,m,y

<script language="Javascript">
function post()
{
	var d = document.getElementById("d");
    var dstr = d.options[d.selectedIndex].value;

  	var m = document.getElementById("m");
    var mstr = m.options[m.selectedIndex].value;

    var y = document.getElementById("y");
    var ystr = y.options[y.selectedIndex].value;

    alert(dstr + "/" + mstr + "/" + ystr);
    
    //submit the form

}
</script>
<input type=button name=b1 value="Go" onclick="post()"/>

Open in new window

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39876737
Using the change event on the selects to populate a hidden text field
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
  $('select').change(function() {
    $('#dob').val($('#jaar').val() + '-' + $('#maand').val() + '-' +  $('#dag').val());
  });
});

</script>
<style type="text/css">
</style>
</head>
<body>
  <div class="dob-container">
    <input type="hidden" id="dob" name="dob" />
    <select id="dag" name="dag">
      <option value="">Dag</option>
      <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>
    </select>
    <select id="maand" name="maand">
      <option value="">Maand</option>
      <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>
    </select>
    <select id="jaar" name="jaar">
      <option value="">Jaar</option>
      <option value="2009">2009</option>
      <option value="2010">2010</option>
      <option value="2011">2011</option>
      <option value="2012">2012</option>
      <option value="2013">2013</option>
    </select>
  </div>
</body>
</html>

Open in new window

0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 39876981
Thanks julianH excellent.
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39877057
You are welcome - thanks for the points.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question