Solved

onSubmit modify variable value

Posted on 2004-04-20
3
659 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Problem to refer to value 8 62
Mouse event to control image and transparency. 4 33
alert(innerHTML); 8 32
Asp in server side with Mssql Server 7 4 26
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

789 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