We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,894 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

javascript function returning undefined variable

I am having trouble getting this to work. I have a form which when the Go button is clicked, calls a function; code for the form & the script listed below:

  <script>
    function RunSelectedReport(reportChoice) {
      alert("reportChoice: " + reportChoice);
      if ( reportChoice === "AllCalls" ) {
        alert("All Calls");
      } else if ( reportChoice === "DaveCalls" ) {
        alert("Dave's Calls");
      }
    }
  </script>

    <form name="daveSvcCallReports" action="@VAR_SECURE_HTTP_@@VAR_FORM_ACTION_URL_@" method="post">
      <input type="radio" name="reportChoice" value="AllCalls">All Calls</input>
      <input type="radio" name="reportChoice" value="DaveCalls">Dave's Calls</input>
      <input type="button" value="Go" onclick="RunSelectedReport(document.daveSvcCallReports.reportChoice.value);"></input>
    </form>

My first alert I placed inside the function, for debugging, returns "Undefined" for the value of reportChoice. However, if I change the line within the form from <input type="button" value="Go" onclick="RunSelectedReport(document.daveSvcCallReports.reportChoice.value);"></input> to <input type="button" value="Go" onclick="RunSelectedReport(1);"></input>, then my function returns a value of 1 for reportChoice. I'm just not seeing what I have wrong with my code, thanks for any help.

2
Contributors
2
Replies
15 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
spowel4
Junior Poster in Training
54 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Accessing the value for a set of radio buttons is not that straight forward. document.form_name.radio_name.value does not work. (Both Nescape and Internet Explorer return "undefined" as value).

http://www.webdevelopersnotes.com/tips/html/finding_the_value_of_a_radio_button.php3

i'm new to javascript but i found this .. hope this helps

azareth
Posting Whiz in Training
245 posts since Apr 2012
Reputation Points: 5
Solved Threads: 18
Skill Endorsements: 0

Actually that did help, thanks!

spowel4
Junior Poster in Training
54 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by azareth

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0624 seconds using 2.66MB