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.
Javascript Functions wont run
Re: Javascript Functions wont run
What are you using to call the function validatePage1? As it is, it won't do anything.
Re: Javascript Functions wont run
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.
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
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.
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
What code are you putting in the button for the onclick event?
Re: Javascript Functions wont run
ValidatePage1()
With an action of JavaScript
With an action of JavaScript
Re: Javascript Functions wont run
I believe you need to add to the onclick event after ValidatePage: Javascript, return true;
Billing clients for your freelance work? Try Minute-2-Minute, the project management, timing, and billing system. Perfect for web developers who charge by the hour. FREE 45-day trial.
Re: Javascript Functions wont run
Added another event after the ValidatePage1() as you suggested, but the field on the form still does not update.
Re: Javascript Functions wont run
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
document.getElementById("RefAthena").value = "40CH/12/12/2023/3776";
I dont know why innerText element does not work
Re: Javascript Functions wont run
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();
I have set up as such:
Event = onclick
Action = javascript
javascript = validatePage1();