Solved

onSubmit modify variable value

Posted on 2004-04-20
3
649 Views
Last Modified: 2012-05-04
Here we go......I have a form with the following fields:
<select name="completedDate_Month">
<select name="completedDate_Day">
<select name="completedDate_Year">
<select name="completedBy">
<input type="text" name="timeSpent">
<input type="hidden" name="completedDate">
<input type="hidden" name="completed" value="False">

Need two things to happen onSubmit:
1) Value of the completedDate_Month/Day/Year need to combine into "mm/dd/yyyy" format and be assigned to completedDate.

2) IF timeSpent && completedBy != "" then completed = "True".

Hope this is clear, THANKS IN ADVANCE!
0
Comment
Question by:FirePits
3 Comments
 
LVL 15

Assisted Solution

by:OMC2000
OMC2000 earned 100 total points
ID: 10869203
<script language="JavaScript">
function onSubmit_function()
{
   document.forms[0].elements.completedDate.value = ''
  + document.forms[0].elements.completedDate_Month.value + '/'
  + document.forms[0].elements.completedDate_Day.value + '/'
  + document.forms[0].elements.completedDate_Year.value;
 if( document.forms[0].elements.timeSpent.value != "" &&
     document.forms[0].elements.completedBy.value != "" ) {
 // I gues you meant document.forms[0].elements.completedBy.selectedIndex != -1, didn't you?
    document.forms[0].elements.completed.value = "True";
    document.forms[0].submit();
 }
 return false;
}
</script>
<form onsubmit="onSubmit_function()">
select name="completedDate_Month">
<select name="completedDate_Day">
<select name="completedDate_Year">
<select name="completedBy">
<input type="text" name="timeSpent">
<input type="hidden" name="completedDate">
<input type="hidden" name="completed" value="False">
</form>
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 200 total points
ID: 10869361
Here my proposal:

<html>
<head>
<script>
function checkCompleted(theForm){
  if(theForm.completedBy.value>"" &&
     theForm.timeSpent.value>""){
    theForm.completedDate.value = theForm.completedDate_Month.value+
      "/"+theForm.completedDate_Day.value+"/"+theForm.completedDate_Year.value;
    theForm.completed.value = "True";
    return true;
  } else {
    alert("Field ComplitedBy or timeSpent are empty.");
    return false;
  }
}
</script>
</head>
<body>
<form onSubmit="return checkCompleted(this)">
<select name="completedDate_Month">
<option value="01">Jan
<option value="02">Feb
<option value="03">Mar
</select>
<select name="completedDate_Day">
<option value="01">01
<option value="02">02
<option value="03">03
</select>
<select name="completedDate_Year">
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
</select>
<select name="completedBy">
<option>-Select-
<option value="Me">Me
<option value="You">You
<option value="Him">Him
</select>
<input type="text" name="timeSpent">
<input type="hidden" name="completedDate">
<input type="hidden" name="completed" value="False">
<input type=submit>
</form>
</body>
</html>

0
 
LVL 1

Author Comment

by:FirePits
ID: 10869691
Both work.......thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now