6 Replies Latest reply on Jul 28, 2006 2:23 AM by Hagster

    Help with a behavior

    Hagster Level 1
      Hello All,

      I have 2 radio buttons one when ticked has the value 'OK' and the other 'NOT OK'

      in the same form I had a selection drop down that allows the user to select 'YES' on selecting yes an on change pop up message set up as a behaviour pos up and say 'by selecting yes you agree to blah blah and you selected XXXXXX'

      How can i get the pop up messed to display 'OK' or 'NOT OK' depending which radio button is ticked this i sbefore submitting the form.

      Or as you tick one of the radio buttons it sets a variable, then i can just display that variable in the pop up message.

      Any pointers please My knowledge of the scripting for onchange things etc is limited.

      Regards Guy
        • 1. Re: Help with a behavior
          Dan Bracuk Level 5
          My pointer is to improve your knowlege of scripting. I learned javascript by buying the book, Teach Yourself Javascript in 24 Hours. It's a good book.
          • 2. Re: Help with a behavior
            Hagster Level 1
            Hello Dan,
            I appriciate your pointer, and i do read alot on the net before I post here, I alsp appriciat you probley get anoyed at people that just use this place for a quick answer with putting no real effort in.
            But I can asure you that I have spent most of my working day trying to figure this one out before I posted to this forum.
            The script below sort of solves a few things

            <script language="JavaScript">
            <!-- Hide
            function test1(form) {
            if (form.text1.checked)
            alert("Please enter a string!")
            else {
            alert(""+form.text1.value+"");
            }
            }
            // -->
            </script>

            <form name="first">
            <input name="text1" type="checkbox" value="yesyes" />

            <select name="gogogo" onchange="test1(this.form)">
            <option value="none">none</option>
            <option value="some">some</option>
            </select>
            </form>

            but doing it that way I cant get <CFOUTPUT> variables to apear in the msg, if i try to change the value of the tickbox like

            <input name="text1" type="checkbox" onClick="if{this.checked}{this.form.text1.value='IAMTICKED'}" >

            allows me to onchange another form element and it pops up a msg with the text1 value in 'IAMTICKED' but I cant seem to get all the bits working together.

            two checkboxes or two radial spots one with value 'OK' one with 'NOTOK'
            and on the change of a drop down list it would show me the value of which ever check/radial is selected.

            Now if I do it with javascript in the header i cant get the cfoutput variables to return in the message
            and if i do it ini the form after the elements i cant get the form element value to return I need both you see and after 4 hours messing about i thought Id ask :) below is complete code to date for this.

            <script type="text/JavaScript">
            <!--
            function MM_popupMsg(msg) {
            alert(msg);
            }
            //-->
            </script>

            *******************

            <input name="review" type="radio" value="ok" />
            <input name="review" type="radio" value="notok" />

            <select name="select" onchange="MM_popupMsg('<cfoutput>#query.name# by selecting \'YES\' you agree that:\r Review = XXXXXX</CFOUTPUT>')">

            <option value=" " selected="selected"></option>
            <option value="YES">YES</option>
            </select>

            the XXXXX is where i need my radio button value to go.

            Kind Regards Guy
            • 3. Help with a behavior
              stitchy
              Hi,

              A good reference site for Javascript is www.irt.org. You'll actually need to loop through the radio button field to see if anything has been selected.
              • 4. Re: Help with a behavior
                wmanu Level 1
                Hi Guy,

                This is another verion, which gives you the same result!

                <script type="text/JavaScript">
                <!--
                function MM_popupMsg(msg) {
                for (i=0;i<document.forms[0].review.length;i++)
                {
                if (document.forms[0].review .checked)
                {
                user_input = document.forms[0].review
                .value;
                }
                }
                alert(msg + user_input);
                }
                //-->
                </script>

                <form NAME="xxx">

                <input name="review" type="radio" value="ok"/>
                <input name="review" type="radio" value="notok" />

                <select name="select" onchange="MM_popupMsg('<cfoutput>#query.name# by selecting \'YES\' you agree that:\r Review =')">
                <option value=" " selected="selected"></option>
                <option value="YES">YES</option>
                </select>

                </form>

                Good luck / Manu.
                • 5. Re: Help with a behavior
                  drforbin1970 Level 1
                  You appear to just need a little help, here's the answer. It's basically hardcoded as opposed to looping thru objects but it gets the job done. You can also modify to make sure the OK button is selected before it can be submitted.

                  <script>
                  function okiedokie(){
                  <!-- stop processing if first dropdown value(blank) is selected -->
                  if(window.document.agreement.yesno.selectedIndex == 0){
                  return false;
                  }
                  if(window.document.agreement.oknot[0].checked==false &&
                  window.document.agreement.oknot[1].checked==false ){
                  alert('You must select either OK or NOT OK')
                  <!-- reset dropdown box -->
                  window.document.agreement.yesno.selectedIndex = 0;
                  return false;
                  }
                  if(window.document.agreement.oknot[0].checked==true){
                  alert('You selected OK');
                  window.document.agreement.yesno.selectedIndex = 0;
                  return false;
                  }
                  if(window.document.agreement.oknot[1].checked==true){
                  alert('You selected NOT OK');
                  window.document.agreement.yesno.selectedIndex = 0;
                  return false;
                  }
                  }
                  </script>

                  <form name="agreement">
                  <input type="radio" name="oknot" value="ok">ok
                  <input type="radio" name="oknot" value="not ok">not ok
                  <select name="yesno" onchange="okiedokie(this)">
                  <option value="">Select Yes or No
                  <option value="Yes">Yes
                  <option value="No">No
                  </select>
                  </form>

                  • 6. Re: Help with a behavior
                    Hagster Level 1
                    Hello,
                    Thank you stitchy, wmanu, drforbin1970, for your replies they helped me alot and my problem is now solved.
                    More to the point my understanding on javascript is a lot better now.

                    Once again thanks

                    Regards Guy