Radio Button onClick Javascript should call only once

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gskoli
    New Member
    • May 2010
    • 23

    #1

    Radio Button onClick Javascript should call only once

    Dear all,
    Let me tell you the scenario , i have called javascript function on radio button selection , Ex.
    Suppose There are 3 Radio Button .
    Let us consider i have clicked on one radio button then
    javascript is called on that and
    it get 'checked' But again if if i clicked on that radio ,
    Then again it will call the javascript .
    So i dont want to let it happen , If radio button value got changed then only javascript should call

    Please help.
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Try using the onchange event instead of the onclick event.

    Comment

    • gskoli
      New Member
      • May 2010
      • 23

      #3
      Well i dint got expected result let me give you some snippet of the code.

      Code:
      <input type='radio' name='productradio' id='proname' value='prod_name' onClick='document.frm.submit();' />Product Name&nbsp;&nbsp; 
      <input type='radio' name='productradio' id='procode' value='prod_code' onClick='document.frm.submit();' />Product Code&nbsp;&nbsp; 
      <input type='radio' name='productradio' id='cat_name' value='cat_name' onClick='document.frm.submit();' />Category Name&nbsp;&nbsp; 
      <input type='radio' name='productradio' id='cat_code' value='cat_code' onClick='document.frm.submit();' />Category Code
      Now if i have selected Category Name and again i am selecting that
      then form should not submit .

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Did you try using the onchange event as I suggested?

        Code:
        <input type='radio' name='productradio' id='proname' value='prod_name' onChange='document.frm.submit();' />Product Name&nbsp;&nbsp; 
        <input type='radio' name='productradio' id='procode' value='prod_code' onChange='document.frm.submit();' />Product Code&nbsp;&nbsp; 
        <input type='radio' name='productradio' id='cat_name' value='cat_name' onChange='document.frm.submit();' />Category Name&nbsp;&nbsp; 
        <input type='radio' name='productradio' id='cat_code' value='cat_code' onChange='document.frm.submit();' />Category Code

        Comment

        • gskoli
          New Member
          • May 2010
          • 23

          #5
          Yes , but dint get result...

          Comment

          • JKing
            Recognized Expert Top Contributor
            • Jun 2007
            • 1206

            #6
            Are you using any serverside code?

            After you submit the form it clears the controls. You would need to save the state of the controls for this to work properly.

            Comment

            • gskoli
              New Member
              • May 2010
              • 23

              #7
              Ya i am using perl , I have solved that problem , But Is there will be pure javascript solution to that . I have saved its status in hidden variable and used that.
              Thanks

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                You seem confused.

                You want a pure JavaScript solution, yet you also want to submit your form. The only way to submit a form without leaving a page is through AJAX, but I have a feeling that this isn't what you are trying to do either.


                Describe exactly what you are trying to do instead of just telling us that "it didn't work."

                Comment

                Working...