Page 1 of 1
Javascript Functions wont run
Posted: Mon Dec 04, 2023 6:53 pm
by Zemicolon
I have added a small piece of javascript to the end of my page
<script type="text/javascript">
function CopyOIC()
{
txt_CN2.value = txt_CN1.value
txt_FN2.value = txt_FN1.value
txt_SN2.value = txt_SN1.value
txt_Tel2.value = txt_Tel1.value
txt_MN2.value = txt_MN1.value
txt_email2.value = txt_email1.value;
}
function validatePage1()
{
alert("hello");
}
</script>
I can get the first function to run fine, but the second function, validatePage1, just wont fire. What am i doing wrong.
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 7:00 pm
by crispy68
What are you using to call the function validatePage1? As it is, it won't do anything.
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 7:57 pm
by Zemicolon
I am calling the function on the onclick event of a button. ValidatePage1 should just display a message as a test.
I have moved the script into its own js file, rather than clutter up the HTML, I hope thats right.
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 8:34 pm
by Zemicolon
index.js, now contains
function CopyOIC()
{
txt_CN2.value = txt_CN1.value
txt_FN2.value = txt_FN1.value
txt_SN2.value = txt_SN1.value
txt_Tel2.value = txt_Tel1.value
txt_MN2.value = txt_MN1.value
txt_email2.value = txt_email1.value;
}
function ValidatePage1()
{
document.getElementById("RefAthena").innerText = "TestData";
}
CopyOIC function works, ValidatePage1 does not work. I have checked the id and it is correct.
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 8:45 pm
by crispy68
What code are you putting in the button for the onclick event?
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 8:50 pm
by Zemicolon
ValidatePage1()
With an action of JavaScript
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 9:09 pm
by gofrank
I believe you need to add to the onclick event after ValidatePage: Javascript, return true;
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 9:19 pm
by Zemicolon
Added another event after the ValidatePage1() as you suggested, but the field on the form still does not update.
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 9:30 pm
by Zemicolon
The following script does fire, and update the form, so I will use that.
document.getElementById("RefAthena").value = "40CH/12/12/2023/3776";
I dont know why innerText element does not work
Re: Javascript Functions wont run
Posted: Mon Dec 04, 2023 11:32 pm
by crispy68
When I place your 1st example in a code object, create a button to fire the validatePage1() function it works for me. Are you sure you set up the button correctly?
I have set up as such:
Event = onclick
Action = javascript
javascript = validatePage1();