Results 1 to 7 of 7

Thread: PHP, javascript n xhtml -- compare variable problem

  1. #1
    Join Date
    Aug 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP, javascript n xhtml -- compare variable problem

    i got a parent window that call out the child window......

    in the child window i successful get the value from the parent window by using opener.document.getElementById.


    because i want show the xhtml based on the value i get, so i had using PHP to compare with the language i get.
    but the problem now is i cant compare although the value same as i get.

    for example:
    in parent window:
    <input type = "hidden" name = "text1" id = "text1" value = "abc">

    in child window:
    <? $getValue = "<script language = 'language'>document.write(opener.document.getElementById('text1').value);</script>";

    if($getValue == "abc")
    {
    echo"<table><tr><td>same</td></tr></table>";
    }
    else
    {
    echo "<table><tr><td>different<td></tr></table>";
    }
    ?>

    but the problem now is, it always show "different" message. y like that de??

    i try to show d $getValue 's value, it show out "abc".

    anyone can help me n tell me what is the problem??


    thanks

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Er, because the string "<script language = 'language'>document.write(opener.document.getElementById('text1').value);</script>" is not equal to the string "abc".

    It's not parsed into "abc" until it reaches the client, by which time your PHP has executed.

    Also, don't use client-side XHTML. See http://www.hixie.ch/advocacy/xhtml.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Er, because the string "<script language = 'language'>document.write(opener.document.getElementById('text1').value);</script>" is not equal to the string "abc".

    It's not parsed into "abc" until it reaches the client, by which time your PHP has executed.

    Also, don't use client-side XHTML. See http://www.hixie.ch/advocacy/xhtml.

    be4 i aslo thinks about that, so i try print out the value i get...

    it print out the value as "abc".

    actually the process for me is got a page that alre show out. i want summary the info in other pages.

    so is can work with php.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    it print out the value as "abc".
    No, it prints out the value "<script language = 'language'>document.write(opener.document.getElementById('text1').value);</script>". The browser converts this to "abc".
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    No, it prints out the value "<script language = 'language'>document.write(opener.document.getElementById('text1').value);</script>". The browser converts this to "abc".

    o..icic

    then isnt we can compare with the other value???

    i try compare with variable with javascript, it work. But if compare with PHP variable then cant work wo..

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can't compare them with PHP, no, unless you call an external Javascript interpreter or something. Even then, you wouldn't be able to use the value of the textbox, to which the server-side interpreter would have no more access than PHP does. You can compare them with Javascript:
    Code:
    <script type="text/javascript">
    if(opener.document.getElementById("text1").value == "$getValue")
      doSomething();
    else
      doSomethingElse();
    </script>
    ... or, you can submit the form then compare them with PHP on the next page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    You can't compare them with PHP, no, unless you call an external Javascript interpreter or something. Even then, you wouldn't be able to use the value of the textbox, to which the server-side interpreter would have no more access than PHP does. You can compare them with Javascript:
    Code:
    <script type="text/javascript">
    if(opener.document.getElementById("text1").value == "$getValue")
      doSomething();
    else
      doSomethingElse();
    </script>
    ... or, you can submit the form then compare them with PHP on the next page.
    this only final soluition can be done on it.....

    is passing 2 next page then d user may said so trouble..... n i also feel that trouble.....

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •