Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
How to call a function within a function.
samuel marin
Greenhorn
Posts: 24
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm trying to call a function within a function.
This Code works. The function TitleOnChange and Show the message "Hello World".
function makeForm() { mypara=document.getElementById("paraID"); myform=document.createElement("form"); myselect = document.createElement("select"); theOption=document.createElement("OPTION"); theText=document.createTextNode("Revenue"); theOption.setAttribute("value","Revenue"); theOption.appendChild(theText); myselect.appendChild(theOption); theOption=document.createElement("OPTION"); theText=document.createTextNode("Expenses"); theOption.appendChild(theText); theOption.setAttribute("value","Expenses"); myselect.appendChild(theOption); //now the select has the options added with their text, values and onChange event myform.appendChild(myselect); mypara.appendChild(myform); myselect.onchange=TitleOnChange; mybreak=document.createElement("p"); myform.appendChild(mybreak); } function TitleOnChange() { alert("Hello World"); }
Now is funny, because if I change the code of the TitleOnChange Function to:
function TitleOnChange() { if (document.form.select.value == Revenue) { alert("Revenue"); } if (document.form.select.value == Expenses) { alert("Expenses"); } }
And this does not work.
I guess I'm doing something wrong in the code above.
I tried all the following combinations:
if (document.form.select.value == Revenue) if (document.form.select.value == "Revenue") if (document.form.select.value = Revenue) if (document.form.select.value = "Revenue")
Thank you very much again
Eric Pascarello
author
Posts: 15385
6
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Do you not indent your code?
if (document.form.select.value == Revenue)
That is saying the value is equal to a variable
Revenue
, not a
string
"Revenue"
.
Have you debugged your code and see what
document.form.select.value
is?
Eric
samuel marin
Greenhorn
Posts: 24
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How can I debugge my code?
That would be great, I didn't konw I could debugge javascript.
Thanks
Eric Pascarello
author
Posts: 15385
6
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Simple as
alert("whatever");
or you can use the built in consoles of the browser [firefox requires Firebug]
Eric
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
All modern browsers (except Firefox) have a built-in debugger. Trying to write client-side code without one is like playing concert piano wearing mittens. Learn the tools at your disposal!
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to get values from a dropdownlist
get all from select multiple
Recognizing a Form
How to Assign a value to a Option of a Combo on the fly
Assign a value to a Option In a Select dropdown on the fly
More...