Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post

    passing values from javascript to php

    hi everyone..please help me with my code
    CODE:
    <script language="javascript">
    function tf()
    {
    if (actiontype.options[actiontype.selectedIndex].value == "1" || actiontype.options[actiontype.selectedIndex].value == "2" || actiontype.options[actiontype.selectedIndex].value == "8" || actiontype.options[actiontype.selectedIndex].value == "15")
    var txt='true';
    else
    var txt='false';
    }
    <script>
    <?php
    if (tf()=='true')
    {
    echo'<tr>
    <td class="table-list-title" id="s">Interview Schedule</td>
    </tr>';
    }
    ?>
    i cant pass the value of txt..please help me how to pass it..

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP is parsed before client scripting, including JS. So you can't transfer JS var's to PHP.

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You can pass it in an URL:

    Code:
    window.location = 'index.php?txt=' + txt;
    and then in PHP access it with

    PHP Code:
    $_GET['txt'

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    what i did is this

    CODE:
    <script language="javascript">
    function tf()
    {
    if (actiontype.options[actiontype.selectedIndex].value == "1" || actiontype.options[actiontype.selectedIndex].value == "2" || actiontype.options[actiontype.selectedIndex].value == "8" || actiontype.options[actiontype.selectedIndex].value == "15")
    var txt='true';
    else
    var txt='false';
    window.location = 'menu.php'index.php?txt=' + txt;
    }


    i tried this one but it did not work..please correct my code.
    if ($_GET[txt]==true)
    echo '<td class="table-list-title" id="s">Interview Schedule</td>';

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by meshi View Post
    Code:
    window.location = 'menu.php'index.php?txt=' + txt;
    You have an extra single-quote in there. It should be a forward-slash.

    PHP Code:
    if ($_GET['txt'] == 'true'

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    still it did'm work

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    this is my edited code..still it did'nt work

    <script language="javascript">
    function tf()
    {
    if (actiontype.options[actiontype.selectedIndex].value == "1" || actiontype.options[actiontype.selectedIndex].value == "2" || actiontype.options[actiontype.selectedIndex].value == "8" || actiontype.options[actiontype.selectedIndex].value == "15")
    var txt='true';
    else
    var txt='false';
    window.location = 'menu.php'?txt=' + txt;
    }
    </script>
    <?php
    if ($_GET['txt']=='true')
    echo '<td class="table-list-title" id="s">Interview Schedule</td>';
    ?>

  • #8
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    <script language="javascript">
    function tf()
    {
    if (actiontype.options[actiontype.selectedIndex].value == "1" || actiontype.options[actiontype.selectedIndex].value == "2" || actiontype.options[actiontype.selectedIndex].value == "8" || actiontype.options[actiontype.selectedIndex].value == "15")
    var txt='true';
    else
    var txt='false';
    if (txt != '<?php echo $_GET['txt']; ?>')
    window.location = 'menu.php?txt=' + txt;
    }
    </script>
    <?php
    if ($_GET['txt']=='true')
    echo 
    '<td class="table-list-title" id="s">Interview Schedule</td>';
    ?>
    Last edited by Mwnciau; 08-31-2007 at 02:54 PM.

  • #9
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    is it not need to call the function tf()..all i need to do is get the value of txt?

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    still it didnt work

  • #11
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    It works fine for me when I remove if (actiontype.options[actiontype.selectedIndex].value == "1" || actiontype.options[actiontype.selectedIndex].value == "2" || actiontype.options[actiontype.selectedIndex].value == "8" || actiontype.options[actiontype.selectedIndex].value == "15") , looks like you have a javascript error.

  • #12
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    i got ur point it seems it works now.tanks.is there any way that it would not load a page.i will ger the value by not loading the page?

  • #13
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    <script language="javascript">
    function tf()
    {
        var actiontype = document.forms['actions']['eventcat'];     

        if (actiontype.options[actiontype.selectedIndex].value == "1")
        {
            document.all('div_one').style.display =  "";    
            document.all('div_two').style.display =  "none";
        }        
        else if (actiontype.options[actiontype.selectedIndex].value == "2")
        {
            document.all('div_one').style.display =  "none";    
            document.all('div_two').style.display =  "";    
        } else {    
            document.all('div_one').style.display =  "none";    
            document.all('div_two').style.display =  "none";
        }        
    }
    </script>

    <form name='actions' method='post'>
    <select name='eventcat' size='1' onChange='tf()'>
        <option value='0'>Select Type</option>
        <option value='1'>One</option>
        <option value='2'>Two</option>
    </select>
    <?php
        
    echo "<div id='div_one' style='display:none;'>";
            echo 
    "<p>One 1 <input type='text' name='one1'>";
            echo 
    "<p>One 2 <input type='text' name='one2'>";
            echo 
    "<p>One 3 <input type='text' name='one3'>";
            echo 
    "<p>One 4 <input type='text' name='one4'>";
            echo 
    "<p>One 5 <input type='text' name='one5'>";
        echo 
    "</div>";

        echo 
    "<div id='div_two' style='display:none;'>";
            echo 
    "<p>Two 1 <input type='text' name='two1'>";
            echo 
    "<p>Two 2 <input type='text' name='two2'>";
            echo 
    "<p>Two 2 <input type='text' name='two3'>";
            echo 
    "<p>Two 3 <input type='text' name='two4'>";
            echo 
    "<p>Two 4 <input type='text' name='two5'>";
        echo 
    "</div>";
    ?>
    </form>
    ???

  • Users who have thanked Bahamut for this post:

    meshi (09-06-2007)

  • #14
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Mechelle I told you Bahamut is the best. hehehhe

  • #15
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    There's no point in using php to echo out those divs etc if js and css is controlling them


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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