0

I have a simple question. I'm sure its easy to everyone... but me. I can't get my drop down box to report the option that was chosen. Can anyone help? This code is generic, but the one that is actually being used is similar to this one. For some reason its not reporting the chosen option from the drop down box to the excel wb. Can anyone let me know what I'm missing? Thanking you in advance!

<SCRIPT LANGUAGE=JAVASCRIPT> 
var currentDate = new Date();
var date1 = currentDate.getDate();
var mon = currentDate.getMonth()+1;
var year = currentDate.getYear();
var today = mon+"/"+date1+"/"+year;
var filePath = "Somefile.xlsx";

function setDate() {
f1.tDate.value=today;
}

function saveToExcel() {
var myApp = new ActiveXObject("Excel.Application");
myApp.visible = false;
var xlCellTypeLastCell = 11;

var myWorkbook = myApp.Workbooks.Open(filePath);
var myWorksheet = myWorkbook.Worksheets(1);
myWorksheet.Activate;
objRange = myWorksheet.UsedRange;
objRange.SpecialCells(xlCellTypeLastCell).Activate;
newRow = myApp.ActiveCell.Row + 1;

strNewCell = "A" + newRow;

myApp.Range(strNewCell).Activate;
myWorksheet.Cells(newRow,1).value = f1.tDate.value;
myWorksheet.Cells(newRow,2).value = f1.tAgent.value;
myWorksheet.Cells(newRow,3).value = f1.tIssid.value;
myWorksheet.Cells(newRow,4).value = f1.tLOB.value;
myWorksheet.Cells(newRow,5).value = f1.tResp.value;
myWorksheet.Cells(newRow,6).value = f1.tResp.value;
myWorksheet.Cells(newRow,7).value = f1.tTaken.value;
myWorksheet.Cells(newRow,8).value = f1.tAlred.value;
myWorksheet.Cells(newRow,9).value = f1.tAlred.value;
myWorksheet.Cells(newRow,10).value = f1.tUnab.value;
myWorksheet.Cells(newRow,11).value = f1.tNotes.value;

myWorkbook.Close(true);
myApp.Workbooks.Close;
myApp.Close;
alert('Data successfully saved');
}
</SCRIPT>
<BODY onLoad="setDate()">
<form name="f1" method="post">
    <h1>Some title</h1><br />
        <h3>Payment Entry Log</h3>
<hr>
<table cellpadding="5" width="475">
<tr>
    <td class="tb_bor"align="left" ><b>Date of Call</b><br />
    <input type=text name=tDate ></td>

    <td class="tb_bor" ><b>Entered By:<br /></b>
    <select name="tAgent" id="tAgent" style="80% !important;">

    <option value="Agent 1" >Agent 1</option>
    <option value="Agent 2" >Agent 2</option>
    <option value="Agent 3" >Agent 3</option>
    <option value="Agent 4" >Agent 4</option>
    <option value="Agent 5" >Agent 5</option>
    <option value="Agent 6" >Agent 6</option>
    <option value="Agent 7" >Agent 7</option>
    <option value="Agent 8" >Agent 8</option>
    <option value="Agent 9" >Agent 9</option>
    <option value="Agent 10" >Agent 10</option>
    </select>
    </td>
</tr>
<tr>
    <td class="tb_bor" ><b>Subscriber ID:</b></td>
    <td align="left" ><input type=text name="tIssid" ></td>
</tr>
<tr>
    <td class="tb_bor" ><b>L.O.B:<br /><br /></b>
    <td align="left" >
    <input id="az" type="radio" value="1" name="tLOB" >AZ<br />
    <input id="ca" type="radio" value="2" name="tLOB" >CA<br />
    <input id="or" type="radio" value="3" name="tLOB" >OR<br /><hr></td>

</tr>
<tr>
    <td width="" class="tb_bor" ><b>Positive Response:<br /><br /></b>
    <td align="left" width="235" >
    <input id="yes" type="radio" value="4" name="tResp" >Yes<br />
    <input id="no"  type="radio" value="5" name="tResp" >No <b><font color="red" size="2">(Indicate only if negative response)</font></b><br /><hr></td>
</tr>
<tr>        
    <td width="" class="tb_bor" ><b>Was a payment taken? <br /><br /></b>
    <td align="left" >
    <input id="yes" type="radio" value="6" name="tTaken" >Yes<br />
    <input id="no"  type="radio" value="7" name="tTaken" >No <br /><hr></td>
</tr>
<tr>        
    <td width="225" class="tb_bor" ><b>Was a payment already made?<br /> <font color="red" size="2">(Must be located in systems, i.e. ABS, CHKSEA, LEDINQ, etc...)</font></b><br /><br /> </b>
    <td align="left" >
    <input id="yes" type="radio" value="8" name="tAlred" >Yes<br />
    <input id="no"  type="radio" value="9" name="tAlred" >No <br /><hr></td>
</tr>
<tr>        
    <td width="225" class="tb_bor" align="right"><b>Could the member be reached?<br /> <font color="red" size="2">(Busy, no awnser , wrong number etc please indicate)</font></b><br /><br /> </b>
    <td align="left" >
    <input id="yes" type="radio" value="10" name="tUnab" >Yes<br />
    <input id="no"  type="radio" value="11" name="tUnab" >No <br /><hr></td>
</tr>

<tr>
    <td class="tb_bor" colspan="3" align="left"><b>Notes:</b><br />
    <textarea rows="6" cols="55" name="tNotes" ></textarea><br />
        <font color="red" size="2">(If a payment was taken, please add notes that were entered in the account)</font></td>
</tr>
</table>

<hr>
<table>
<tr>
    <td align="center" colspan="2">
        <input type="reset" name="Reset" value="Clear" >
        <input type="button" name=save value="Submit" onClick='saveToExcel();'>
    </td>
</tr>
</table>
</form>
</BODY>
user1739280
  • 73
  • 1
  • 3
  • 14

1 Answers1

0

The code actually worked for me. I'm not sure what error you are receiving.

What I did:

  1. Opened the html file on a PC (Windows 8) from Internet Explorer, being sure to enable ActiveX when presented with the option.
  2. Created the Excel file, put it in the same location as the html file and closed it.
  3. Updated the path to the Excel file in the javascript. I used an absolute path (beginning at "C:/") and used forward slashes only.
  4. Changed the selection in the drop down box in Internet Explorer and then clicked "Post" with different selections.

The Excel file was updated appropriately upon inspection.

Also, you should be able to see any error messages from the running of your javascript code in Internet Explorer's "Developer Tools" using the "Console".

PerpetualStudent
  • 822
  • 9
  • 17
  • Well, you see, When I tried to run the program it will not record whatever option I chose in the drop down box. It just leaves the cell blank. I don't get why because I've named it with id's and such and even pointed it in the right direction. I know it works for the other input boxes because the data inputted in them shows up in excel. I just don't get what I'm doing wrong. My system maybe? Outdated possibly? – user1739280 Jun 11 '14 at 03:03
  • I'm not sure. I can't seem to reproduce the problem. Maybe try updating Internet Explorer to a later version? Are you receiving any errors in the console? – PerpetualStudent Jun 11 '14 at 12:44
  • My apologies, I've updated the code. It seems to be working now but the radio buttons now don't report. This is the issue I was having with the drop down. Any ideas? – user1739280 Jun 12 '14 at 03:29
  • That is a different issue. Take a look here: http://stackoverflow.com/questions/9618504/get-radio-button-value-with-javascript It seems you can't refer to the "name" attribute of a tag when it's not unique. Probably you should ask a different question if you're still confused. – PerpetualStudent Jun 12 '14 at 16:22
  • Also, if it seems I've solved your original problem, can you accept my answer? – PerpetualStudent Jun 12 '14 at 16:25