Jump to content

JavaScript stopped working?


Recommended Posts

Hi all --

I have an input form datapage that uses JavaScript to perform two functions to insert data into hidden fields in the table. One function grabs the text from one of the input fields and duplicates it in a hidden field. The other function performs a calculation on two numbers from two input fields to get an average, and inserts that average into a hidden field. This datapage has worked flawlessly for months, but suddenly today, those two functions stopped working. In the first function, instead of the duplicated text, I get "NaN" inserted in the hidden field. In the other function, nothing at all is inserted in the hidden field -- it's left blank. I've made no changes to either the datapage or the related tables. Here are the JavaScript functions, FWIW -- but again, these have been working fine for months:

<script language="javascript" type="text/javascript">

function calculate () {

var loE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeLow.value);
var hiE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeHigh.value);
var avgE = (loE + hiE)/2;
var avgR = avgE.toFixed(2);
document.getElementById('caspioform').InsertRecorddine_entreeAvg.value = avgR;

}

document.getElementById('caspioform').onsubmit = calculate;

function addName() {

var restName = parseFloat(document.getElementById('caspioform').InsertRecorddine_name.value);
document.getElementById('caspioform').InsertRecorddine_nameSearch.value = restName;

}

document.getElementById('caspioform').onsubmit = addName;

</script>

I've tried this on both Mac and PC, in both Firefox and IE, with the same results. I've also used the direct datapage URL, so it doesn't seem to be anything on the web page the datapage is embedded in. Anyone have an idea why this would suddenly stop working?

Thanks!

-- Mike

Link to comment
Share on other sites

Hi Mike,

I think there is a small error in your javacript code.

In the addName function you are doing parseFloat to a text field and hence you are getting error NaN(not a number) error.

Also onSubmit you are calling two functions separately, so only the one called last(in this case addName) is being executed. So instead of calling them separately, call the first function calculate() in the second function.

Try this.

<script language="javascript" type="text/javascript">

function calculate () {

var loE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeLow.value);
var hiE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeHigh.value);
var avgE = (loE + hiE)/2;
var avgR = avgE.toFixed(2);
document.getElementById('caspioform').InsertRecorddine_entreeAvg.value = avgR;
return;
}

//document.getElementById('caspioform').onsubmit = calculate;

function addName() {

calculate();
var restName = document.getElementById('caspioform').InsertRecorddine_name.value;
document.getElementById('caspioform').InsertRecorddine_nameSearch.value = restName;

}

document.getElementById('caspioform').onsubmit = addName;

</script>

Hope this helps.

Megha

Link to comment
Share on other sites

Thank you! Those fixes did the trick! I'm puzzled though why it had been working previously. Initially I only had the first function, and it worked fine for some time. I added the second function later and did a few entries with success -- at least, I thought I did ... At any rate, it's working now, and I learned something about parseFloat and onSubmit!

-- Mike

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...