[Solved] I want to add text field in html dynamically using jquery or javascript to a particular button [closed]


i am showing you in javascript.
First make your html file look like this

<div class="rButtons">
  <input type="radio" name="numbers" value="10" onclick="uncheck();" />10
  <input type="radio" name="numbers" value="20"  onclick="uncheck();" />20
  <input type="radio" name="numbers" value="other" onclick="check(this);"/>other
  <input type="text" id="other_field" name="other_field" onblur="checktext(this);"/>
</div>

In the second step write this css code to initially set the text field invisible.

<style type="text/css">
#other_field
{
    visibility: hidden;
}
</style>

Finally use this javascript code to validate the user’s behaviour

<script type="text/javascript">
    function uncheck()
     {
       document.getElementById('other_field').style.visibility = "hidden";
     }
    function check(inputField)
    {
        if(inputField.checked)
        {
            document.getElementById('other_field').style.visibility = "visible";
        }
    }
    function checktext(inputField)
    {
        if(isNaN(inputField.value))
        {
            alert('only numbers are allowed..');
            return false;
        }
        else if( (inputField.value % 10 ) != 0)
        {
            alert('only multiples of 10..');
            return false;
        }
        else
        {
            return true;
        }

    }
    </script>

The first function detects if user clicked the “other” radio button and displays the hidden
text filed..

The second function validates the input field as per your requirements…

6

solved I want to add text field in html dynamically using jquery or javascript to a particular button [closed]