Javascript Functions wont run

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
Zemicolon
 
 
Posts: 6
Joined: Wed Nov 22, 2023 11:01 pm

Javascript Functions wont run

Post 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.
User avatar
crispy68
 
 
Posts: 2995
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Javascript Functions wont run

Post by crispy68 »

What are you using to call the function validatePage1? As it is, it won't do anything.
Zemicolon
 
 
Posts: 6
Joined: Wed Nov 22, 2023 11:01 pm

Re: Javascript Functions wont run

Post 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.
Zemicolon
 
 
Posts: 6
Joined: Wed Nov 22, 2023 11:01 pm

Re: Javascript Functions wont run

Post 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.
User avatar
crispy68
 
 
Posts: 2995
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Javascript Functions wont run

Post by crispy68 »

What code are you putting in the button for the onclick event?
Zemicolon
 
 
Posts: 6
Joined: Wed Nov 22, 2023 11:01 pm

Re: Javascript Functions wont run

Post by Zemicolon »

ValidatePage1()

With an action of JavaScript
User avatar
gofrank
 
 
Posts: 196
Joined: Sun Dec 30, 2007 2:43 am
Location: Florida, USA

Re: Javascript Functions wont run

Post by gofrank »

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.
Zemicolon
 
 
Posts: 6
Joined: Wed Nov 22, 2023 11:01 pm

Re: Javascript Functions wont run

Post by Zemicolon »

Added another event after the ValidatePage1() as you suggested, but the field on the form still does not update.
Zemicolon
 
 
Posts: 6
Joined: Wed Nov 22, 2023 11:01 pm

Re: Javascript Functions wont run

Post 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
User avatar
crispy68
 
 
Posts: 2995
Joined: Thu Oct 23, 2014 12:43 am
Location: Acworth, GA
Contact:

Re: Javascript Functions wont run

Post 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();
Post Reply