Solved

onSubmit modify variable value

Posted on 2004-04-20
3
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

756 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