Jump to content

How can i set a "yes" radio button to require an action

- - - - -

  • Please log in to reply
6 replies to this topic

#1
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
HOW CAN I SET A RADIO BUTTON TO REQUIRE AN ACCOUNT NUMBER IF YES IS SELECTED.


 <label>

      <input type="radio" name="radio" id="yes" value="yes" />Yes</label> />

    <label>


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
Do you mean that if yes is selected, the user need to add an account number in a textbox?

by the way, your HTML is broken by the last /> on second row.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
yes Orjan that's what i mean. can you help on this?
thanks for the heads up on that, ithappened on the copy/paste

Orjan said:

Do you mean that if yes is selected, the user need to add an account number in a textbox?

by the way, your HTML is broken by the last /> on second row.


#4
dmanjrod

dmanjrod

    Newbie

  • Members
  • Pip
  • 7 posts
You can use javascript to show another input field once the user clicks on yes.

#5
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
do you know where i can find that script? or can you post it here for me. thank you for your help

dmanjrod said:

You can use javascript to show another input field once the user clicks on yes.


#6
dmanjrod

dmanjrod

    Newbie

  • Members
  • Pip
  • 7 posts
Something like this:
First, here's your CSS which will hide the field for entering a user id when it loads.
<style type="text/css">

#uid {

    display: none;

}

</style>
Then here's your form:
<label><input type="radio" name="radio" id="yes" value="yes" onClick="toggleuid('show');"/>Yes</label>

<label><input type="radio" name="radio" id="no" value="no" onClick="toggleuid('hide');"/>No</label>

<br />

<label id="uid">User id <input type="text" name="uidfield" /></label>

And finally, this is the script that will handle the showing and hiding of the field.
<script type="text/javascript">

    function toggleuid(a) {

    if (a == "show") {

        document.getElementById('uid').style.display = 'block';

    }

    else {

        document.getElementById('uid').style.display = 'none';

    }

}

</script>

When yes is clicked, the javascript function toggleuid() is called with an argument of 'show' and when no is clicked it will call it with an argument of 'hide'. You might want to look into Jquery since it can be done much easier and with much better aesthetics.

#7
Emil

Emil

    Newbie

  • Members
  • PipPip
  • 11 posts
super helpful you are. works like a charm. thank you very much.
email

dmanjrod said:

Something like this:
First, here's your CSS which will hide the field for entering a user id when it loads.
<style type="text/css">

#uid {

    display: none;

}

</style>
Then here's your form:
<label><input type="radio" name="radio" id="yes" value="yes" onClick="toggleuid('show');"/>Yes</label>

<label><input type="radio" name="radio" id="no" value="no" onClick="toggleuid('hide');"/>No</label>

<br />

<label id="uid">User id <input type="text" name="uidfield" /></label>

And finally, this is the script that will handle the showing and hiding of the field.
<script type="text/javascript">

    function toggleuid(a) {

    if (a == "show") {

        document.getElementById('uid').style.display = 'block';

    }

    else {

        document.getElementById('uid').style.display = 'none';

    }

}

</script>

When yes is clicked, the javascript function toggleuid() is called with an argument of 'show' and when no is clicked it will call it with an argument of 'hide'. You might want to look into Jquery since it can be done much easier and with much better aesthetics.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users