PHP string with alert message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyberlei
    New Member
    • Sep 2007
    • 28

    PHP string with alert message

    Hey guys, i was trying to use alert message for php string,but dunno why the alert can`t be displayed, so please help me where i did wrong, THANKS SO MUCH
    here is the code:[code=javascript]
    <SCRIPT LANGUAGE=JAVASC RIPT>
    function disp_alert()
    {
    alert = "Serial Number Must Be Start With S";
    }
    </SCRIPT>[/code]

    php code:
    [code=php]
    if(substr($sn,0 ,1) == "S")
    else
    {
    $message="Seria l Number Must Be Start With S.";
    } [/code]
    JS code:
    [code=html]
    <input name="sn" type="text" onKeyDown="disp _alert()" "if(event.keyCo de==13) event.keyCode=9 ;"size="26" >[/code]
    Last edited by pbmods; Oct 16 '07, 12:16 AM. Reason: Added CODE tags.
  • cyberlei
    New Member
    • Sep 2007
    • 28

    #2
    just changed code like this:
    [code=php]
    <%
    if(substr($sn,0 ,1) == "S")

    else
    {
    $message="Seria l Number Must Be Start With S";
    echo "alert(".$messa ge.")";
    }
    %>
    [/code]
    still same, the alert window not display.
    Last edited by pbmods; Oct 16 '07, 12:16 AM. Reason: Added CODE tags.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, cyberlei.

      Please use CODE tags when posting source code:

      &#91;CODE=ph p]
      PHP code goes here.
      &#91;/CODE]

      Comment

      • cyberlei
        New Member
        • Sep 2007
        • 28

        #4
        sorry about that.

        I already fixed that alert message issue, Thanks anyway

        Comment

        • cyberlei
          New Member
          • Sep 2007
          • 28

          #5
          Originally posted by cyberlei
          sorry about that.

          I already fixed that alert message issue, Thanks anyway

          Just post the answer here for someone who have same issue on that.

          [CODE=php]

          echo '<script>alert( "Serial Number Must Be Start With S");</script>';

          [/CODE]

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, cyberlei.

            Thanks for posting your solution.

            Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

            Comment

            • prashante18
              New Member
              • Feb 2008
              • 1

              #7
              I have problem that there is alert msg showing but my php page (web page) is blank white page When alert box removes that page again get appears,I want the should appear and at the same time alert msg also be shown.Plz, help me!
              Thanks!
              Prashant

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by prashante18
                I have problem that there is alert msg showing but my php page (web page) is blank white page When alert box removes that page again get appears,I want the should appear and at the same time alert msg also be shown.Plz, help me!
                Thanks!
                Prashant
                Tell properly what you are trying to do, and what's happening?

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by prashante18
                  I have problem that there is alert msg showing but my php page (web page) is blank white page When alert box removes that page again get appears,I want the should appear and at the same time alert msg also be shown.Plz, help me!
                  Thanks!
                  Prashant
                  have a look at setTimeOut() or setInterval()

                  Comment

                  • yasmine
                    New Member
                    • Feb 2008
                    • 64

                    #10
                    Originally posted by cyberlei
                    Just post the answer here for someone who have same issue on that.

                    [CODE=php]

                    echo '<script>alert( "Serial Number Must Be Start With S");</script>';

                    [/CODE]

                    Hi,
                    Thanx 4 ur code.
                    But i'm having some problem with it.
                    The alert msg works. But when i clicks OK button, it wil goes to next reference page and not stands at the same page.
                    Why its happened?
                    What can I do?
                    Plz...Help me out...
                    Thanx n Regards
                    Yas

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Originally posted by yasmine
                      Hi,
                      Thanx 4 ur code.
                      But i'm having some problem with it.
                      The alert msg works. But when i clicks OK button, it wil goes to next reference page and not stands at the same page.
                      Why its happened?
                      What can I do?
                      Plz...Help me out...
                      Thanx n Regards
                      Yas
                      What are you doing after the alert?...

                      You must return false after this. in the same loop as alert is.

                      Comment

                      • yasmine
                        New Member
                        • Feb 2008
                        • 64

                        #12
                        Originally posted by hsriat
                        What are you doing after the alert?...

                        You must return false after this. in the same loop as alert is.
                        yah, i wrote it.
                        Can u give me the proper code for it...???

                        Thanx n Regards
                        Yas.

                        Comment

                        • hsriat
                          Recognized Expert Top Contributor
                          • Jan 2008
                          • 1653

                          #13
                          Originally posted by yasmine
                          yah, i wrote it.
                          Can u give me the proper code for it...???

                          Thanx n Regards
                          Yas.
                          [html]<form onsubmit="retur n onSubmitOfForm( );" action="abc.php " method="post | get">[/html]
                          [CODE=javascript]function onSubmitOfForm( ) { //use this on onsubmit of form, or onlick of submit button.
                          if (CONDITION==tru e) { //whichever condition you are verifying
                          return true;
                          else {
                          alert ('MESSAGE'); //your message in case condition not fulfilled
                          return false;
                          }
                          }[/CODE]

                          If this is not what you needed, send your code. Only then I can help.

                          PS: Ask such questions in Javascript Forum

                          Comment

                          • yasmine
                            New Member
                            • Feb 2008
                            • 64

                            #14
                            Originally posted by hsriat
                            [html]<form onsubmit="retur n onSubmitOfForm( );" action="abc.php " method="post | get">[/html]
                            [CODE=javascript]function onSubmitOfForm( ) { //use this on onsubmit of form, or onlick of submit button.
                            if (CONDITION==tru e) { //whichever condition you are verifying
                            return true;
                            else {
                            alert ('MESSAGE'); //your message in case condition not fulfilled
                            return false;
                            }
                            }[/CODE]

                            If this is not what you needed, send your code. Only then I can help.

                            PS: Ask such questions in Javascript Forum

                            Thanx a lot.....
                            It's working....
                            But i'm having a doubt.
                            Is it possible to embed the same code with in PHP code...???

                            Thanx n Regards
                            Yas

                            Comment

                            • hsriat
                              Recognized Expert Top Contributor
                              • Jan 2008
                              • 1653

                              #15
                              Originally posted by yasmine
                              Thanx a lot.....
                              It's working....
                              But i'm having a doubt.
                              Is it possible to embed the same code with in PHP code...???

                              Thanx n Regards
                              Yas
                              Embed it in the <SCRIPT> tag in the <HEAD> of HTML

                              PS: It may help you if you read some basics of JavaScript

                              Comment

                              Working...