delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

        }
//-->
</script>
<input type="radio" name="optiontype" value="value1" onclick="getAmt('fy');"> Option1
<input type="radio" name="optiontype" value="value2" onclick="getAmt('tr');"> Option2
<input type="radio" name="optiontype" value="value3" onclick="getAmt(tnr');"> Option3
<div id="deposit"></div>
What am I doing wrong?
Thanks


I have 3 radio buttons and based on which is clicked I want to write html to a div. So far nothing is happening and it seems that the onclick is not being done at all or tried.
This is what I have:
Code:
  1.    <script type="text/javascript">
  2. <!--
  3.          function getAmt(ss){
  4.                 if(ss == "fy"){
  5.                         document.getElementById("deposit").innerHTML = '<input type="text" name="amount" value="500"/>';
  6.                 }
  7.                 elseif(ss=="tr"){
  8.                         document.getElementById("deposit").innerText = '<input type="text" name="amount" value="500"/>';
  9.                 }
  10.                 elseif(ss=="tnr"){
  11.                         document.getElementById("deposit").innerText = '<input type="text" name="amount" value="250"/>';
  12.                 }
  13.         }
  14. //-->
  15. </script>
  16. <input type="radio" name="optiontype" value="value1" onclick="getAmt('fy');"> Option1
  17. <input type="radio" name="optiontype" value="value2" onclick="getAmt('tr');"> Option2
  18. <input type="radio" name="optiontype" value="value3" onclick="getAmt(tnr');"> Option3
  19. <div id="deposit"></div>
Copy Code
What am I doing wrong?
Thanks

TOP

loulou,
There were a few minor errors:
1.  Elseif should be two words - else if
2.  Your second two conditions used innerText instead of innerHTML
3.  Your third radio button forgot the tick (') before tnr.. it read ....(tnr')  and should be ...('tnr')
Please see my corrections below:
Code:
  1.    <script type="text/javascript">
  2. <!--
  3.          function getAmt(ss){
  4.                 if(ss == "fy"){
  5.                 document.getElementById("deposit").innerHTML = '<input type="text" name="amount" value="500"/>';
  6.                 }
  7.                 [b]else if[/b](ss=="tr"){
  8.                 document.getElementById("deposit")[b].innerHTML[/b] = '<input type="text" name="amount" value="500"/>';
  9.                 }
  10.                 [b]else if[/b](ss=="tnr"){
  11.                 document.getElementById("deposit")[b].innerHTML[/b] = '<input type="text" name="amount" value="250"/>';
  12.                 }
  13.         }
  14. //-->
  15. </script>
  16. <input type="radio" name="optiontype" value="value1" onclick="getAmt('fy');"> Option1
  17. <input type="radio" name="optiontype" value="value2" onclick="getAmt('tr');"> Option2
  18. <input type="radio" name="optiontype" value="value3" onclick="getAmt[b]('[/b]tnr');"> Option3
  19. <div id="deposit"></div>
Copy Code
Hope this Helps!,
coffeeCoder

TOP

or just add
document.getElementById("deposit").text if it's plain text you're adding.  Both innerHTML and text are IE specific.  The standard for text is textContent, but IE doesn't employ this standard and uses text.  One workaround would be to prototype .text in FF and use .text instead of textContent.

TOP

tried out my solution in IE, Firefox, Chrome, and Safari, and all work.



        }
//-->
</script>
<input type="radio" name="optiontype" value="value1" onclick="getAmt('fy');"> Option1
<input type="radio" name="optiontype" value="value2" onclick="getAmt('tr');"> Option2
<input type="radio" name="optiontype" value="value3" onclick="getAmt(tnr');"> Option3
<div id="deposit"></div>
What am I doing wrong?
Thanks

TOP

Back Forum