Great on the subject line huh?
Ok, I have a form that will add extra fields based on how many times a user clicks on a link. Then when the user clicks on the execute button it should pass the information entered to notepad. I would like this to work for as many extra fields as the user adds. But it will only work for one extra field at this point because I only have variables & if statements setup for one. I would like to have a loop or something that will accomodate as many fields as the user adds. Any help or a point in the right direction would be appreciated!
The full code is at the bottom, but here are the lines of code I need to loop? or something:
HourlyOrFlatT1 = ""
TaskAmountT1 = ""
if(document.Form_1.HourlyOrFlatT1_field.value != ""{HourlyOrFlatT1 = document.Form_1.HourlyOrFlatT1_field.value}
if(document.Form_1.TaskAmountT1_field.value != ""{TaskAmountT1 = document.Form_1.TaskAmountT1_field.value}
if(HourlyOrFlatT1 != ""{Form_1_content += HourlyOrFlatT1 + "~"}
if(TaskAmountT1 != ""{Form_1_content += TaskAmountT1 + "~"}
Here is a sample of my code so far:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "<html lang="en">
<head>
<SCRIPT LANGUAGE="JavaScript"><!-- Begin
function generate(){
//Define variables that will be assigned to the values entered by the user
Client = ""
AcctMgr = ""
HourlyOrFlatT1 = ""
TaskAmountT1 = ""
NewSession = ""
//Define the variable that will be composed of the above variables.
Form_1_content = ""
//Determine if a value is entered in one of the form fields, if so, assign it to its variable.
if(document.Form_1.Client_field.value != ""{Client = document.Form_1.Client_field.value}
if(document.Form_1.AcctMgr_field.value != ""{AcctMgr = document.Form_1.AcctMgr_field.value}
if(document.Form_1.HourlyOrFlatT1_field.value != ""{HourlyOrFlatT1 = document.Form_1.HourlyOrFlatT1_field.value}
if(document.Form_1.TaskAmountT1_field.value != ""{TaskAmountT1 = document.Form_1.TaskAmountT1_field.value}
//Compile the 'Form_1_content' variable based on the variables that were assigned a value
//This block of code uses the ~ character instead of the \n to make a new line for vbscript.
if(Client != ""{Form_1_content += Client + "~A~"}
if(AcctMgr != ""{Form_1_content += AcctMgr + "~"}
if(HourlyOrFlatT1 != ""{Form_1_content += HourlyOrFlatT1 + "~"}
if(TaskAmountT1 != ""{Form_1_content += TaskAmountT1 + "~"}
//Define starting & ending variables
Form_1_start = ""
Form_1_end = "End Stuff Here"
//Tell function where to dump the value generated.
document.Form_1.output.value = Form_1_start + Form_1_content + Form_1_end
}
//This will add extra 'task' forms
addlink = 2;
tNum = 0;
function displayTask()
{
tNum = tNum + 1;
var str='<table bgcolor="#DDDDDD" align="center" border="1" width="100%">';
str+= ' <tr>';
str+= ' <td bgcolor="#000000" colspan="2"><font color="#FFFFFF"><a name="Task' + tNum + '">Task ' + tNum + '</a></font></td>';
str+= ' </tr>';
str+= ' <tr>';
str+= ' <td colspan="2">Hourly/Flat: <select name="HourlyOrFlatT' + tNum + '_field" size="1" class="txt">';
str+= ' <option value="1" selected>Hourly';
str+= ' <option value="2">Flat Rate';
str+= ' <option value="3">Per Piece</option>';
str+= ' </select></td>';
str+= ' </tr>';
str+= ' <tr>';
str+= ' <td colspan="2">Amount: <input type="TEXT" size="10" name="TaskAmountT' + tNum + '_field" value class="txt"></td>';
str+= ' </tr>';
str+= ' <TR> ';
str+= ' <TD><a href="#" onClick="displayTask();return false;">Add Task</a></span></TD>';
str+= ' </TR>';
str+= ' </table>';
str+= '<div id="somediv' + addlink + '"></div>';
somediv = 'somediv' + tNum;
document.all[somediv].innerHTML = str;
addlink = addlink + 1;
}
//--></SCRIPT>
<SCRIPT LANGUAGE=vbscript>
function ShowPassed
Dim strPassedValue
Dim NewSession
Dim strUserName
Dim strPassword
Dim ss
Dim starttime,waittime,currenttime
waittime = 3
strPassedValue = document.Form_1.output.value
NewSession = document.Form_1.NewSession_field.value
strUserName = document.Form_1.UserName_field.value + "{enter}"
strPassword = document.Form_1.Password_field.value + "{enter}"
if NewSession = 1 then
MsgBox("Clicking OK will begin process."
Set ss = CreateObject("WScript.Shell"
ss.run "C:\WINNT\NOTEPAD.EXE",1
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys strUserName
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys strPassword
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys "1{enter}JOBREQUEST{ENTER}3" + strPassedValue
Set ss = nothing
else
MsgBox("ActivateApp, still working on..."
end if
end function
</SCRIPT>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>
<body class="txt">
<form name="Form_1">
<table bgcolor="#DDDDDD" align="center" border="1" width="100%">
<tr>
<td bgcolor="#000000" colspan="2"><font color="#FFFFFF">Create Job Request</font></td>
</tr>
<tr>
<td colspan="2">Client number: <input type="TEXT" size="10" name="Client_field" value class="txt"></td>
</tr>
<tr>
<td>Account Manager: <select name="AcctMgr_field" size="1" class="txt">
<option value="0" selected>Select
<option value="1">John Doe
<option value="2">Jane Jones</option>
</select></td>
<tr>
<TD><a href="#" onClick="displayTask();return false;">Add Task</a></TD>
</tr>
</table>
<div id="somediv1"></div>
<table bgcolor="#DDDDDD" align="center" border="1" width="100%">
<tr>
<td>Run in new Session? <select name="NewSession_field" size="1" class="txt">
<option value="1" selected>Yes
<option value="2">No</option>
</select></td>
<td>user name: <input type="TEXT" size="10" name="UserName_field" value class="txt">
password: <input type="password" size="10" name="Password_field" value class="txt"></td>
</tr>
<tr>
<td align="center"><input type="RESET" value="Default Settings"> <input type="SUBMIT" value="Save Settings"></td>
<td align="center"><input name="button" type="button" onclick="generate()" value="Append"> <input type="button" value="Execute!" id="button2" name="button2" onclick="generate(),ShowPassed()"></td>
</tr>
<tr>
<td colspan="2">Form 1 Output: <textarea type="TEXT" name="output" rows="10" cols="55"></textarea></td>
</tr>
</table>
</form>
</body>
</html>
Ok, I have a form that will add extra fields based on how many times a user clicks on a link. Then when the user clicks on the execute button it should pass the information entered to notepad. I would like this to work for as many extra fields as the user adds. But it will only work for one extra field at this point because I only have variables & if statements setup for one. I would like to have a loop or something that will accomodate as many fields as the user adds. Any help or a point in the right direction would be appreciated!
The full code is at the bottom, but here are the lines of code I need to loop? or something:
HourlyOrFlatT1 = ""
TaskAmountT1 = ""
if(document.Form_1.HourlyOrFlatT1_field.value != ""{HourlyOrFlatT1 = document.Form_1.HourlyOrFlatT1_field.value}
if(document.Form_1.TaskAmountT1_field.value != ""{TaskAmountT1 = document.Form_1.TaskAmountT1_field.value}
if(HourlyOrFlatT1 != ""{Form_1_content += HourlyOrFlatT1 + "~"}
if(TaskAmountT1 != ""{Form_1_content += TaskAmountT1 + "~"}
Here is a sample of my code so far:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "<html lang="en">
<head>
<SCRIPT LANGUAGE="JavaScript"><!-- Begin
function generate(){
//Define variables that will be assigned to the values entered by the user
Client = ""
AcctMgr = ""
HourlyOrFlatT1 = ""
TaskAmountT1 = ""
NewSession = ""
//Define the variable that will be composed of the above variables.
Form_1_content = ""
//Determine if a value is entered in one of the form fields, if so, assign it to its variable.
if(document.Form_1.Client_field.value != ""{Client = document.Form_1.Client_field.value}
if(document.Form_1.AcctMgr_field.value != ""{AcctMgr = document.Form_1.AcctMgr_field.value}
if(document.Form_1.HourlyOrFlatT1_field.value != ""{HourlyOrFlatT1 = document.Form_1.HourlyOrFlatT1_field.value}
if(document.Form_1.TaskAmountT1_field.value != ""{TaskAmountT1 = document.Form_1.TaskAmountT1_field.value}
//Compile the 'Form_1_content' variable based on the variables that were assigned a value
//This block of code uses the ~ character instead of the \n to make a new line for vbscript.
if(Client != ""{Form_1_content += Client + "~A~"}
if(AcctMgr != ""{Form_1_content += AcctMgr + "~"}
if(HourlyOrFlatT1 != ""{Form_1_content += HourlyOrFlatT1 + "~"}
if(TaskAmountT1 != ""{Form_1_content += TaskAmountT1 + "~"}
//Define starting & ending variables
Form_1_start = ""
Form_1_end = "End Stuff Here"
//Tell function where to dump the value generated.
document.Form_1.output.value = Form_1_start + Form_1_content + Form_1_end
}
//This will add extra 'task' forms
addlink = 2;
tNum = 0;
function displayTask()
{
tNum = tNum + 1;
var str='<table bgcolor="#DDDDDD" align="center" border="1" width="100%">';
str+= ' <tr>';
str+= ' <td bgcolor="#000000" colspan="2"><font color="#FFFFFF"><a name="Task' + tNum + '">Task ' + tNum + '</a></font></td>';
str+= ' </tr>';
str+= ' <tr>';
str+= ' <td colspan="2">Hourly/Flat: <select name="HourlyOrFlatT' + tNum + '_field" size="1" class="txt">';
str+= ' <option value="1" selected>Hourly';
str+= ' <option value="2">Flat Rate';
str+= ' <option value="3">Per Piece</option>';
str+= ' </select></td>';
str+= ' </tr>';
str+= ' <tr>';
str+= ' <td colspan="2">Amount: <input type="TEXT" size="10" name="TaskAmountT' + tNum + '_field" value class="txt"></td>';
str+= ' </tr>';
str+= ' <TR> ';
str+= ' <TD><a href="#" onClick="displayTask();return false;">Add Task</a></span></TD>';
str+= ' </TR>';
str+= ' </table>';
str+= '<div id="somediv' + addlink + '"></div>';
somediv = 'somediv' + tNum;
document.all[somediv].innerHTML = str;
addlink = addlink + 1;
}
//--></SCRIPT>
<SCRIPT LANGUAGE=vbscript>
function ShowPassed
Dim strPassedValue
Dim NewSession
Dim strUserName
Dim strPassword
Dim ss
Dim starttime,waittime,currenttime
waittime = 3
strPassedValue = document.Form_1.output.value
NewSession = document.Form_1.NewSession_field.value
strUserName = document.Form_1.UserName_field.value + "{enter}"
strPassword = document.Form_1.Password_field.value + "{enter}"
if NewSession = 1 then
MsgBox("Clicking OK will begin process."
Set ss = CreateObject("WScript.Shell"
ss.run "C:\WINNT\NOTEPAD.EXE",1
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys strUserName
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys strPassword
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys "1{enter}JOBREQUEST{ENTER}3" + strPassedValue
Set ss = nothing
else
MsgBox("ActivateApp, still working on..."
end if
end function
</SCRIPT>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>
<body class="txt">
<form name="Form_1">
<table bgcolor="#DDDDDD" align="center" border="1" width="100%">
<tr>
<td bgcolor="#000000" colspan="2"><font color="#FFFFFF">Create Job Request</font></td>
</tr>
<tr>
<td colspan="2">Client number: <input type="TEXT" size="10" name="Client_field" value class="txt"></td>
</tr>
<tr>
<td>Account Manager: <select name="AcctMgr_field" size="1" class="txt">
<option value="0" selected>Select
<option value="1">John Doe
<option value="2">Jane Jones</option>
</select></td>
<tr>
<TD><a href="#" onClick="displayTask();return false;">Add Task</a></TD>
</tr>
</table>
<div id="somediv1"></div>
<table bgcolor="#DDDDDD" align="center" border="1" width="100%">
<tr>
<td>Run in new Session? <select name="NewSession_field" size="1" class="txt">
<option value="1" selected>Yes
<option value="2">No</option>
</select></td>
<td>user name: <input type="TEXT" size="10" name="UserName_field" value class="txt">
password: <input type="password" size="10" name="Password_field" value class="txt"></td>
</tr>
<tr>
<td align="center"><input type="RESET" value="Default Settings"> <input type="SUBMIT" value="Save Settings"></td>
<td align="center"><input name="button" type="button" onclick="generate()" value="Append"> <input type="button" value="Execute!" id="button2" name="button2" onclick="generate(),ShowPassed()"></td>
</tr>
<tr>
<td colspan="2">Form 1 Output: <textarea type="TEXT" name="output" rows="10" cols="55"></textarea></td>
</tr>
</table>
</form>
</body>
</html>