0

Here is my JS code.

<script type="text/javascript">
  function showfield6(name){
    if(name=='Other')
      document.getElementById('div6').innerHTML='Other: <input type="text" name="pubfer" />';
    else
      document.getElementById('div6').innerHTML='';
  }
</script>

And:

<select name="pubfer" id="pubfer" onchange="showfield6(this.options[this.selectedIndex].value)">
  <option selected="selected">Please select ...</option>
  <option value="Thesis">Thesis</option>
  <option value="Paper">Paper</option>
  <option value="Report">Report</option>
  <option value="Short Notes">Refrigerator</option>
  <option value="Technical Notes">Technical Notes</option>
  <option value="Other">Other</option>
</select>
<div id="div6"></div>

I can't use else if statements.

How can I use my JS code to use it?

Specimen (Choose)
Bone
   Side 
    Elements
    Pathology
    Measurements  (import) excel

Teeth
   Side 
    Measurements report

Hair

If the user selects "Specimen", open fields Bone, Teeth, Hair. If the user selects "Bone" new text fields are going to open. Their names are "side, elements" etc. If the user select "Teeth", new text fields will open.

How can I create this form?

3
  • 12
    "I cant use else if statements.." Why not? Commented Jul 20, 2013 at 11:26
  • BTW, title is not for typing tags. Oh, and why is php tagged? Commented Jul 20, 2013 at 11:40
  • Your code didn't match with your example. Please give an example which related with your code. OR update your code. Commented Jul 20, 2013 at 12:13

2 Answers 2

1

Seems like an academic question else there wouldn't be this "can't use else if statements" I guess. Therefore, the only solution I could give you would be to look into switch case statements.

**EDIT: Following @Stano comment, here is a bit more details about how to use a switch case statement.

Switch case can be used when you have multiple possible values for a variable and want to execute a code based on that value.

For example, your showfield6() function could look something like this:

function showfield6(id) {

  switch(id) {  //Begin swith case
    case "Bone":    //When id=="Bone"
      //Execute code block here
      break;        //If you do not add this break, the code in the next case will be executed
    case "Teeth":   //When id=="Teeth"
      //Execute code for "Teeth"
      break;
    case "Hair": 
      //Code block
      break;
    case default:   //Anything that wasnt't matched aboved (id=="SomethingElse")
      //Handle other cases here
  }

}

For more information on swith case statements: http://www.w3schools.com/js/js_switch.asp

Sign up to request clarification or add additional context in comments.

1 Comment

Good point @Stano, just edited my answer with more details... Guess I was just too lazy since I hadn't had my first coffee yet. :P
0

Yes, may be it will help you definitely. Have a look on this.

http://www.w3schools.com/js/js_switch.asp

-Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.