Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Daniel Leavey

Referencing Form Elements 143 - 150

Recommended Posts

The Switch Conditional exercise on pages 143 - 150 makes us of an undefined variable, var cost; and I'm not sure what role it plays in the code. Do the cost elements in the switch statements load the value into the undefined variable var cost depending upon which condition is met in the document's type value?

 

I can remove these two lines of code, as well as the undefined variable, var cost, and still see the membership form run:

 

 

 var type = document.getElementById('type');
 var years = document.getElementById('years');

 

Why did we create a reference to the document element years when it seems not to be used in the script?

 

 

Many mysteries have unfolded in this exercise.

 

Share this post


Link to post
Share on other sites

The Switch Conditional exercise on pages 143 - 150 makes us of an undefined variable, var cost; and I'm not sure what role it plays in the code. Do the cost elements in the switch statements load the value into the undefined variable var cost depending upon which condition is met in the document's type value?

Yes, that's exactly it. The cost variable is set based on the condition met by the switch statement.

 

I can remove these two lines of code, as well as the undefined variable, var cost, and still see the membership form run:

What do you mean by this? In what respect does it run? I'm willing to bet that if you erase everything you mentioned and then submit the form, either an error will occur or you will not get the intended result.

 
The type and years variables are used to store the values entered for the corresponding inputs on the form. Without type, you can't execute the switch statement, and without years, you can't calculate the proper cost.
In other words, they're both required.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...