• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

onSubmit modify variable value

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
FirePits
Asked:
FirePits
2 Solutions
 
OMC2000Commented:
<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
 
ZvonkoSystems architectCommented:
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
 
FirePitsAuthor Commented:
Both work.......thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now