I am trying to populate a <select> element via Ajax. It works great in FF, but I get an unknown runtime error in IE.
HTML:
<select id="emp_select" name="emp_select">
<option value=" ">Please enter a store</option>
</select>
Javascript:
$("#store").blur(function() {
populateDropdowns();
});
...
function populateDropdowns() {
var store = $("#store").val();
if (store.length != 4) {
alert("Store # must be 4 digits!");
$("#store").focus();
return false;
}
var xhrJSON = new XMLHttpRequest();
var xhrEmpSelect = new XMLHttpRequest();
var xhrMgrSelect = new XMLHttpRequest();
var jsonDone = false;
var empSelectDone = false;
var mgrSelectDone = false;
$("#processing-dialog").dialog({
width: 300,
height: 150
});
xhrJSON.onreadystatechange = function() {
if (xhrJSON.readyState == 4) {
if (xhrJSON.status == 200) {
var js = document.createElement('script');
js.type = 'text/javascript';
js.innerHTML = xhrJSON.responseText;
var scr = document.getElementsByTagName('script')[1];
scr.parentNode.insertBefore(js,scr);
jsonDone = true;
if (jsonDone && empSelectDone && mgrSelectDone) {
$("#processing-dialog").dialog("close");
$("#processing-dialog").dialog("destroy");
return true;
}
} else {
return false;
}
}
}
xhrEmpSelect.onreadystatechange = function() {
if (xhrEmpSelect.readyState == 4) {
if (xhrEmpSelect.status == 200) {
$("#emp_select").html(xhrEmpSelect.responseText);
empSelectDone = true;
if (jsonDone && empSelectDone && mgrSelectDone) {
$("#processing-dialog").dialog("close");
$("#processing-dialog").dialog("destroy");
return true;
}
} else {
return false;
}
}
}
xhrMgrSelect.onreadystatechange = function() {
if (xhrMgrSelect.readyState == 4) {
if (xhrMgrSelect.status == 200) {
$("#mgr_select").html(xhrMgrSelect.responseText);
mgrSelectDone = true;
if (jsonDone && empSelectDone && mgrSelectDone) {
$("#processing-dialog").dialog("close");
$("#processing-dialog").dialog("destroy");
return true;
}
} else {
return false;
}
}
}
var url = "ajax.cgi";
var JSONdata = "action=generateJSON&store=" + store;
var EmpSelectData = "action=generateEmpSelect&store=" + store;
var MgrSelectData = "action=generateMgrSelect&store=" + store;
xhrJSON.open("POST",url);
xhrJSON.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhrJSON.send(JSONdata);
xhrEmpSelect.open("POST",url);
xhrEmpSelect.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhrEmpSelect.send(EmpSelectData);
xhrMgrSelect.open("POST",url);
xhrMgrSelect.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhrMgrSelect.send(MgrSelectData);
}
The blur handler calls a function to populate (all) the different select elements, plus a JavaScript object that holds an associative array of all the employees to match up a name with an employee id that is returned as the values of the options in both select elements.
XHR Text returned (for xhrJSON, content-type=application/json):
var empArray = new Array({ id:"12345678", title:"The Title", code:"C123", name:"John Doe"},...);
XHR Text returned for (xhrEmpSelect, content-type=text/html):
<option value=" ">Select One</option>
<option value="John Doe">John Doe</option>
<option value="Joe Blow">Joe Blow</option>
...
<option value="other">Other...</option>
</select>
Similar text is returned for xhrMgrSelect, content-type=text/html
So in FF everything works great, the JS Object comes across and is inserted into the DOM and both <select> elements are populated as well. BUT in IE, I get an unknown runtime error in the xhrJSON.onreadystatechange handler where I try and set the js.innerHTML to the xhrJSON.responseText.
What am I doing wrong?
Try using js.text = xhrJSON.responseText; instead of innerHTML. I believe the issue you are encountering has to do with the fact that you can't insert HTML into a <script> block.
Since you are setting the script you should use innerText instead of innerHTML. Try this.
js.innerText = xhrJSON.responseText;
//Since FF do not sussport innerText but it does support textContent
js.textContent = xhrJSON.responseText;
I would advice you to migrate your code to jQuery which will be much simpler, readable, and easy to maintain without any worries of cross browser support. jQuery does everything for you.
To set the contents of a HTMLScriptElement object, (created using document.createElement('script');) you should use the setText method of the object instead of trying to set the innerHTML of the script.
js.setText(xhrJSON.responseText);
See the W3 specification from the link above.
Related
I have a Contact Form that utilizes Google Scripts. It successfully sends the email and formats it decently to my inbox, but there are 2 problems:
-I need it so that IF var key is equal to 'Action', then do not display it in the email it sends. Because right now, "Action send_message" is getting included in the email and I don't like that.
For this, I have unsuccessfully tried things like:
for (var idx in order) {
var key = order[idx];
//Skip this entry into the email output if it is the Action
if( key === 'Action') {
continue
}
It seems to not react to this code at all.
-I also need it so that if a city is selected, e.g. Alachua, that the email says 'Alachua' instead of 'Florida_Alachua'. But I can't add a NAME to an option since apparently options don't have that property. I also can't do the quick fix of changing the VALUE of the <option> to resolve this step, because of other code I have that conflicts with this route.
Google Scripts Code:
/******************************************************************************
* This tutorial is based on the work of Martin Hawksey twitter.com/mhawksey *
* But has been simplified and cleaned up to make it more beginner friendly *
* All credit still goes to Martin and any issues/complaints/questions to me. *
******************************************************************************/
// if you want to store your email server-side (hidden), uncomment the next line
var TO_ADDRESS = "myemail#email.com";
// spit out all the keys/values from the form in HTML for email
// uses an array of keys if provided or the object to determine field order
function formatMailBody(obj, order) {
var result = "";
if (!order) {
order = Object.keys(obj);
}
// loop over all keys in the ordered form data
for (var idx in order) {
var key = order[idx];
result += "<h4 style='text-transform: capitalize; margin-bottom: 0'>" + key + "</h4><div>" + sanitizeInput(obj[key]) + "</div>";
// for every key, concatenate an `<h4 />`/`<div />` pairing of the key name and its value,
// and append it to the `result` string created at the start.
}
return result; // once the looping is done, `result` will be one long string to put in the email body
}
// sanitize content from the user - trust no one
// ref: https://developers.google.com/apps-script/reference/html/html-output#appendUntrusted(String)
function sanitizeInput(rawInput) {
var placeholder = HtmlService.createHtmlOutput(" ");
placeholder.appendUntrusted(rawInput);
return placeholder.getContent();
}
function doPost(e) {
try {
Logger.log(e); // the Google Script version of console.log see: Class Logger
record_data(e);
// shorter name for form data
var mailData = e.parameters;
// names and order of form elements (if set)
var orderParameter = e.parameters.formDataNameOrder;
var dataOrder;
if (orderParameter) {
dataOrder = JSON.parse(orderParameter);
}
// determine recepient of the email
// if you have your email uncommented above, it uses that `TO_ADDRESS`
// otherwise, it defaults to the email provided by the form's data attribute
var sendEmailTo = (typeof TO_ADDRESS !== "undefined") ? TO_ADDRESS : mailData.formGoogleSendEmail;
// send email if to address is set
if (sendEmailTo) {
MailApp.sendEmail({
to: String(sendEmailTo),
subject: "Contact form submitted",
// replyTo: String(mailData.email), // This is optional and reliant on your form actually collecting a field named `email`
htmlBody: formatMailBody(mailData, dataOrder)
});
}
return ContentService // return json success results
.createTextOutput(
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": error}))
.setMimeType(ContentService.MimeType.JSON);
}
}
/**
* record_data inserts the data received from the html form submission
* e is the data received from the POST
*/
function record_data(e) {
var lock = LockService.getDocumentLock();
lock.waitLock(30000); // hold off up to 30 sec to avoid concurrent writing
try {
Logger.log(JSON.stringify(e)); // log the POST data in case we need to debug it
// select the 'responses' sheet by default
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheetName = e.parameters.formGoogleSheetName || "responses";
var sheet = doc.getSheetByName(sheetName);
var oldHeader = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
var newHeader = oldHeader.slice();
var fieldsFromForm = getDataColumns(e.parameters);
var row = [new Date()]; // first element in the row should always be a timestamp
// loop through the header columns
for (var i = 1; i < oldHeader.length; i++) { // start at 1 to avoid Timestamp column
var field = oldHeader[i];
var output = getFieldFromData(field, e.parameters);
row.push(output);
// mark as stored by removing from form fields
var formIndex = fieldsFromForm.indexOf(field);
if (formIndex > -1) {
fieldsFromForm.splice(formIndex, 1);
}
}
// set any new fields in our form
for (var i = 0; i < fieldsFromForm.length; i++) {
var field = fieldsFromForm[i];
var output = getFieldFromData(field, e.parameters);
row.push(output);
newHeader.push(field);
}
// more efficient to set values as [][] array than individually
var nextRow = sheet.getLastRow() + 1; // get next row
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
// update header row with any new data
if (newHeader.length > oldHeader.length) {
sheet.getRange(1, 1, 1, newHeader.length).setValues([newHeader]);
}
}
catch(error) {
Logger.log(error);
}
finally {
lock.releaseLock();
return;
}
}
function getDataColumns(data) {
return Object.keys(data).filter(function(column) {
return !(column === 'formDataNameOrder' || column === 'formGoogleSheetName' || column === 'formGoogleSendEmail' || column === 'honeypot');
});
}
function getFieldFromData(field, data) {
var values = data[field] || '';
var output = values.join ? values.join(', ') : values;
return output;
}
Contact Form HTML
<section id="contact-form">
<form id="gform"
class="contact-form" method="post"
action="(Google Scripts URL)"
enctype="text/plain">
<p>
<label for="name">Your Name <font face="Arial" color="red">*</font></label>
<input type="text" style="height:35px;" class="heighttext required" name="name" id="name" class="required" title="* Please provide your name">
</p>
<p>
<label>Your Location <font face="Arial" color="red">*</font></label>
<select name="Location" id="column_select" style="height:35px;" class="required" title=" * Please provide your location">
<option selected value="col00">-- State --</option>
<option value="Alabama">Alabama</option>
<option value="California">California</option>
<option value="Florida">Florida</option>
</select>
<select name="City" id="layout_select" style="height:35px;">
<option disabled selected value="Florida">-- City --</option>
<option name="Alachua" value="Florida_Alachua">Alachua</option>
<option name="Alford" value="Florida_Alford">Alford</option>
</select>
</p>
<p>
<input type="submit" value="Send Message" id="submit" class="pp-btn special">
<img src="images/ajax-loader.gif" id="contact-loader" alt="Loading...">
<input type="hidden" name="action" value="send_message">
</p>
</form>
</section><!-- #contact-form -->
Form Handler Javascript
(function() {
function validEmail(email) { // see:
var re = /^([\w-]+(?:\.[\w-]+)*)#((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}
function validateHuman(honeypot) {
if (honeypot) { //if hidden form filled up
console.log("Robot Detected!");
return true;
} else {
console.log("Welcome Human!");
}
}
// get all data in form and return object
function getFormData() {
var form = document.getElementById("gform");
var elements = form.elements;
var fields = Object.keys(elements).filter(function(k) {
return (elements[k].name !== "honeypot");
}).map(function(k) {
if(elements[k].name !== undefined) {
return elements[k].name;
// special case for Edge's html collection
}else if(elements[k].length > 0){
return elements[k].item(0).name;
}
}).filter(function(item, pos, self) {
return self.indexOf(item) == pos && item;
});
var formData = {};
fields.forEach(function(name){
var element = elements[name];
// singular form elements just have one value
formData[name] = element.value;
// when our element has multiple items, get their values
if (element.length) {
var data = [];
for (var i = 0; i < element.length; i++) {
var item = element.item(i);
if (item.checked || item.selected) {
data.push(item.value);
}
}
formData[name] = data.join(', ');
}
});
// add form-specific values into the data
formData.formDataNameOrder = JSON.stringify(fields);
formData.formGoogleSheetName = form.dataset.sheet || "responses"; // default sheet name
formData.formGoogleSendEmail = form.dataset.email || ""; // no email by default
console.log(formData);
return formData;
}
function handleFormSubmit(event) { // handles form submit without any jquery
event.preventDefault(); // we are submitting via xhr below
var data = getFormData(); // get the values submitted in the form
/* OPTION: Remove this comment to enable SPAM prevention, see README.md
if (validateHuman(data.honeypot)) { //if form is filled, form will not be submitted
return false;
}
*/
if( data.email && !validEmail(data.email) ) { // if email is not valid show error
var invalidEmail = document.getElementById("email-invalid");
if (invalidEmail) {
invalidEmail.style.display = "block";
return false;
}
} else {
disableAllButtons(event.target);
var url = event.target.action; //
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
// xhr.withCredentials = true;
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
console.log( xhr.status, xhr.statusText )
console.log(xhr.responseText);
//document.getElementById("gform").style.display = "none"; // hide form
/*
var thankYouMessage = document.getElementById("thankyou_message");
if (thankYouMessage) {
thankYouMessage.style.display = "block";
}
*/
return;
};
// url encode form data for sending as post data
var encoded = Object.keys(data).map(function(k) {
return encodeURIComponent(k) + "=" + encodeURIComponent(data[k])
}).join('&')
xhr.send(encoded);
}
}
function loaded() {
console.log("Contact form submission handler loaded successfully.");
// bind to the submit event of our form
var form = document.getElementById("gform");
form.addEventListener("submit", handleFormSubmit, false);
};
document.addEventListener("DOMContentLoaded", loaded, false);
function disableAllButtons(form) {
var buttons = form.querySelectorAll("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].disabled = true;
}
}
})();
finally, this is the extra code that would break if I simply tried changing the value of option to, e.g., 'Alachua' instead of 'Flordia_Alachua'. https://jsfiddle.net/hmatt843/504dgmqy/19/
Thanks for any and all help.
Try console.log(key) before if( key === 'Action'). I think you'll find that key never equals 'Action', exactly. Looks like you'll need if( key === 'action'), instead.
If you wish to remove part of string value, try the replace method: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
It also looks like you're trying to work with elements[k].name when you mean to be working with elements[k].value.
I believe your code should look something like...
function(k) {
if(elements[k].value !== undefined) {
return elements[k].value.replace('Florida_', '');
// special case for Edge's html collection
} else if(elements[k].length > 0){
return elements[k].item(0).value.replace('Florida_', '');
}
}
... or something to that effect.
In the future, you may want to make it easier for folks trying to help you by posting only the portions of code your having trouble with, and breaking your questions into different posts. A lot to sift through up there.
Hope this helped.
The split() method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
Var splitValue = elements[k].item(0).value.split("");
splitValue[1] will give you a string of characters after the delimeter () in this case.
<input class="c-search__textbox c-form__textbox" id="top-query" list="top-json-datalist" onkeyup="suggest(this)" autocomplete="off" type="text" name="q" value="" placeholder="Type something . . .">
<datalist id="top-json-datalist"></datalist>
function suggest(elem) {
if(elem.id == "query") {
document.getElementById("query").disabled = false;
var dataList = document.getElementById('json-datalist');
var input = document.getElementById('query');
} else if (elem.id == "top-query") {
document.getElementById("top-query").disabled = false;
var dataList = document.getElementById('top-json-datalist');
var input = document.getElementById('top-query');
}
var request = new XMLHttpRequest();
// Handle state changes for the request.
request.onreadystatechange = function(response) {
if (request.readyState === 4) {
if (request.status === 200) {
var data = JSON.parse(request.responseText);
var jsonOptions = data.hits;
dataList.innerHTML = '';
jsonOptions.forEach(function(item) {
var option = document.createElement('option');
option.value = item["query"];
dataList.appendChild(option);
});
}
}
};
request.open('GET','https://api.lite.s4p.jp/v1/suggest&query='+input.value,true);
request.send();
As you can see I am able to load datalist items from ajax call.
I am able to see the items in the dropdown list. However, the problem is that when the item is selected, the drop-down still remains.
Thank You!
I'm wondering whether you are doing something in your suggest function that is causing a problem, does it work if you remove onkeyup="suggest(this)"?
The other thing is that support for datalist seems quite buggy according to caniuse. Have you tried in other browsers?
Sorry, would have just commented but I don't have enough rep yet.
I am trying to build a custom control using HTML and JQuery. The control will display a text value. The user can enter a variety of key/value pairs. Currently, I have the following HTML
<input id="keyValue" type="text" />
<select id="keyName" name="keyName">
<option value="k1">Some Name</option>
<option value="key2">Another Name</option>
<option value="arg3">How about one more</option>
</select>
<input id="keyValuePairs" type="hidden" />
The value displayed in "keyValue" will change based on the option the user chooses. I'm trying to keep the mappings in keyValuePairs. In an attempt to do this, I have the following:
$('#keyName').on('change', function() {
var key = $('#keyName').val();
var keyValuePairs = $('#keyValuePairs').val();
if (keyValuePairs[key]) {
$('#keyValue').val(keyValuePairs[key]);
} else {
$('#keyValue').val('');
}
});
$('#keyValue').on('change', function() {
var key = $('#keyName').val();
var keyValuePairs = $('#keyValuePairs').val();
if (!keyValuePairs ) {
keyValuePairs = {};
}
keyValuePairs[key] = $(this).val();
$('#keyValuePairs').val(JSON.stringify(keyValuePairs));
});
For some reason, the text field always shows a blank string after I choose another key. I believe it has something to do with how I'm encoding or decoding the JSON. When I add console.log to the keyValuePairs I noticed that sometimes quotes are included and other times they're not. Yet, the code looks correct to me.
What am I doing wrong?
I believe you should JSON.parse $('#keyValuePairs').val() after you've read it (since you stringify the pairs when you set the value)
UPDATE:
You must also ensure that the value is not empty:
$('#keyName').on('change', function() {
var key = $('#keyName').val();
var val = $('#keyValuePairs').val();
if (val && val.length > 0) {
var keyValuePairs = JSON.parse(val);
if (keyValuePairs[key]) {
$('#keyValue').val(keyValuePairs[key]);
} else {
$('#keyValue').val('');
}
}
});
$('#keyValue').on('change', function() {
var key = $('#keyName').val();
var val = $('#keyValuePairs').val();
var keyValuePairs;
if (val && val.length > 0) {
keyValuePairs = JSON.parse(val);
} else {
keyValuePairs = {};
}
keyValuePairs[key] = $(this).val();
$('#keyValuePairs').val(JSON.stringify(keyValuePairs));
});
json_encode(#keyValuePairs) //encoding
json_decode(#keyValuePairs) //decoding
datatype : json
function sortPosts() {
var pSort = document.getElementById('pSort').selectedIndex;
var pstSort = document.getElementById('pSort').options;
var sorted = pstSort[pSort].value;
var hr = new XMLHttpRequest();
var url = "...";
var vars = "sort="+sorted;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if (hr.readyState === 4 && hr.status === 200) {
var return_data = hr.responseText;
var cntnt = document.getElementById('content');
while ((cntnt.lastChild !== '
<select id="pSort">
<option value="all" selected="true">All Posts</option>
<option value="friends">Friends\' Posts</option>
<option value="following">Following\'s Posts</option></select>' && cntnt.childNodes.length !== 1) || (cntnt.firstChild != '<select id="pSort"><option value="all" selected="true">All Posts</option><option value="friends">Friends\' Posts</option><option value="following">Following\'s Posts</option></select>' && cntnt.childNodes.length != 1)) {
cntnt.removeChild(cntnt.lastChild);
}
document.getElementById('content').innerHTML += return_data;
document.getElementById('content').style.opacity = '1.0';
}
}
hr.send(vars);
document.getElementById('content').style.opacity = "0.5";
}
I need to remove every child element in the div#content element until only the select element remains. I would say every child element except the first, but it seems there's an invisible text node in Chrome within the div#content element that I have no control over.
Or if you have a better way to keep the select element on the page while ajax loads new content and removes the old content, I'd love to hear it.
To remove all but the first child:
while (cntnt.childNodes.length > 1) {
cntnt.removeChild(cntnt.lastChild);
}
You could also filter by the id of the select you want to save
while (cntnt.lastChild.id !== 'pSort') {
cntnt.removeChild(cntnt.lastChild);
}
Or your could just get the innerHTML of pSort and append it with the ajax response right away, without having to loop to remove elements
cntnt.innerHTML = document.getElementById('pSort').innerHTML + return_data;
You can do it this way:
const firstElementChild = yearRangeToSelector.firstElementChild;
selectElement.innerHTML = '';
selectElement.append(firstElementChild);
I have an html file which passes values into a java servlet to insert into the database. Here is my code:
<html>
<head>
<script type="text/javascript">
function masinsert(id)
{
var currentTime=new Date();
var button = document.getElementById("m"+id);
button.onclick="";
button.value="Inserting";
var partnumber = document.getElementById("partnumber"+id).value;
var itemcost = document.getElementById("itemcost"+id).value;
var itemlistprice = document.getElementById("itemlistprice"+id).value;
var sUnitMeasKey = document.getElementById("UnitMeasKey"+id);
var sPurchProdLine = document.getElementById("PurchProdLine"+id);
var sItemClassKey = document.getElementById("itemclasskey"+id);
var UMKselected = getSelected(sUnitMeasKey);
var PPLselected = getSelected(sPurchProdLine);
var ICKselected = getSelected(sItemClassKey);
function handleHttpResponse()
{
if (http.readyState == 4) {
button.value="Imported";
}
}
var http = getHTTPObject(); // We create the HTTP Object
var tempUrl = "\MASInsert2";
tempUrl += "?partnumber="+partnumber+"&"+"itemcost="+itemcost+"&"+"itemlistprice="+itemlistprice+"&"+"UnitMeasure="+UMKselected+"&"+"PurchProdLine="+PPLselected+"&"+"itemclasskey="+ICKselected;
alert(tempUrl);
http.open("POST", tempUrl, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getSelected(ele)
{
return ele.options[ele.selectedIndex].value;
}
function getHTTPObject(){
var xmlhttp;
/*#cc_on
#if (#_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (E) {
xmlhttp = false;
}
}
#else
xmlhttp = false;
#end #*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
</script>
</head>
<body>
<form name=bob method=get>
<input type=hidden id="partnumber321" name="partnumber321" value="884910U">
<input type=hidden id="itemcost321" name="itemcost321" value="1027.39">
<input type=hidden id="itemlistprice321" name="itemlistprice321" value="1129.0">
<input type=hidden id="itemdescription321" name="itemdescription321" value="XSERIES 306M SS P4 3.0GHZ 1MB">
<select id="UnitMeasKey321" name="UnitMeasKey321"><option value="112">Each</select>
<select id="PurchProdLine321" name="PurchProdLine321"><option value="18">IBM</select>
<select id="itemclasskey321" name="itemclasskey321"><option value="48">Hardware</select>
<input id="m321" type="button" onclick="masinsert('321')" value="Add">
</form>
</body>
</html>
When I hit the button, the alert(partnumber) returns null (firefox) or object (IE). Am I passing these values incorrectly for the servlet to process? Any ideas why? shouldn't it return a value?
thanks in advance
Firefox is returning null because there is no ID by that name. Call GetElementByName if you don't want to assign ids to your inputs.
IE is returning an object because DOM elements are objects. You need to check one of its attributes (value most likely) to see what it's actually set to.
IE shouldn't return an object, but it naively assumes that GetElementById is the same as GetElementByName.
Classic IE bug ID vs. Name. You will either need to specify and use id attributes, or use getElementsByName (beware it will return a "set" of matches) or the form.elements[nameOrIndex] format.
e.g.
alert(document.forms[myFormNameOrIndex].elements[myElementNameOrIndex].value);
I see three things that are odd (and probably the issues):
How are you setting the id "partnumber"? IE giving you an object seems like you've only set the name attribute of the input box, not the id attribute.
You have to get the value of those properties to construct a url: partnumber.value
You are using a GET method for what seems like an insert. This should be a POST.