Onchange Event in Dropdown

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #16
    Originally posted by waqasahmed996
    Code:
    <?php
     [U]$country = [/U]echo '<script type="text/JavaScript"> echo value; </script>'; 
     ?>
    echo is not a function and thus cannot be assigned to a variable.

    Comment

    • waqasahmed996
      New Member
      • Jun 2008
      • 160

      #17
      thanks chandhseke but i am asking from Dormilich

      Comment

      • chandhseke
        New Member
        • Jun 2009
        • 92

        #18
        The output of your above code is as follows..
        while i select INDIA from drop down, a confirm box comes up with a question: Are you a INDIA citizen( where value is taken as INDIA).. But this is not my concern, my concern ihere s when the user clicks OK or CANCEL then i want this action to be recorded or stored in a variable, and this value should be stored in a text box

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #19
          Originally posted by chandhseke
          now if the user clicks OK/CANCEL, i need to store a true/false value in a varialbe and then assign it to asp variable or a text box. How can i do this
          To assign it to a text box:
          Code:
          document.getElementById("textboxid").value = val;
          This would require a submit to be passed to ASP. Another option is to pass it in the URL and change the page immediately:
          Code:
          location.href = "asppage.asp?val=" + val;
          If you want to avoid a page reload, use Ajax.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #20
            Originally posted by chandhseke
            my concern ihere s when the user clicks OK or CANCEL then i want this action to be recorded or stored in a variable, and this value should be stored in a text box
            what do you mean by "text box"? a <textarea> or a <input> or a <div> element?

            Comment

            • waqasahmed996
              New Member
              • Jun 2008
              • 160

              #21
              you can write like
              document.getEle mentById('txtbo x').innerHTML = 'INDIA'

              Dormilich i remove echo from my code even then it is not working

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #22
                Originally posted by waqasahmed996
                Dormilich i remove echo from my code even then it is not working
                to get output you have to use echo or one of the print() functions

                Comment

                • waqasahmed996
                  New Member
                  • Jun 2008
                  • 160

                  #23
                  sorry Dormilich i am still unable to understand. please tell me what should i write exactly

                  Code:
                  <?php
                   $country = echo '<script type="text/JavaScript">  value; </script>'; 
                   ?>

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #24
                    I guess
                    Code:
                    <?php
                     echo '<script type="text/JavaScript"> // whatever code </script>'; 
                     ?>
                    will do.

                    EDIT: if your problem is not related to chandhseke's problem, I'll move the corresponding posts to a new thread in the PHP forum.

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #25
                      Originally posted by waqasahmed996
                      what is mistake in my following code. where variable 'value' is javascript variable
                      Code:
                      <?php
                       $country = echo '<script type="text/JavaScript"> echo value; </script>'; 
                       ?>
                      Besides the PHP problem, you're mixing JavaScript and PHP incorrectly. You can use PHP (or any server-side language) to generate JavaScript code during page load, but you can't use this kind of code to run PHP after the page has loaded.

                      Comment

                      • chandhseke
                        New Member
                        • Jun 2009
                        • 92

                        #26
                        In vbscript, i am using message box If the user clicks OK button.. I want to assing a value to a text box <input>..Plea se help me out in this

                        Code:
                        <Script lang="VBScript>
                        dim a
                        dim res= Yes
                        a=MsgBox("you pressed ok",VbYesNo)
                        
                        if a = VbYes then
                        
                        <i want to assign the variable "res" to a text box below>
                        </script>
                        
                        <html>
                        <head><body>
                        <input type="text" name="test" value=''>
                        </head></html>
                        Last edited by acoder; Jun 28 '09, 09:42 PM. Reason: Added [code] tags

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #27
                          Two questions:
                          1. Is this related to the original problem?
                          2. Why are you using VBScript when JavaScript is more cross-browser friendly?

                          PS. please use [code] tags when posting code.

                          Comment

                          • chandhseke
                            New Member
                            • Jun 2009
                            • 92

                            #28
                            As there is NO window object with YES and NO buttons in Javascript, i am making use of both Javascript and VB script..

                            In javascript i am using selectedIndex to track the selected item from the drop down, within IF conditon i am calling VBscript function(contai ns a MsgBox) if the result is true...

                            Now within VBscript i need to write a condition, If the user clicks on Yes button then i want to assign some value to a textbox so that i can save this text box value in the database.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #29
                              You do realise that this would restrict your site to IE only? You can phrase your question so that the options for confirm() (OK/Cancel) are suitable. Are you sure you still want to go with VBScript?

                              If you do, the method will be similar to what has been suggested earlier. Set the value of the text box like this:
                              Code:
                              document.getElementById("textboxid").value = val;
                              where "textboxid" is the ID of the text box and val is the value that needs to be assigned.

                              Comment

                              • chandhseke
                                New Member
                                • Jun 2009
                                • 92

                                #30
                                Thanks for the reply.
                                But as per the requirement, YES or NO should be the only options..that is the reason i am using VBscript... Anyways i will speak to the requestors regarding the above subject... If i am using VBscript what will be the syntax in VBscript to assign a value to a text box..??

                                Comment

                                Working...