Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-31-2007, 02:20 PM   PM User | #1
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
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..
meshi is offline   Reply With Quote
Old 08-31-2007, 02:24 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
PHP is parsed before client scripting, including JS. So you can't transfer JS var's to PHP.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 08-31-2007, 02:25 PM   PM User | #3
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
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'
Mwnciau is offline   Reply With Quote
Old 08-31-2007, 02:37 PM   PM User | #4
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
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>';
meshi is offline   Reply With Quote
Old 08-31-2007, 02:39 PM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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'
Inigoesdr is offline   Reply With Quote
Old 08-31-2007, 02:47 PM   PM User | #6
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
still it did'm work
meshi is offline   Reply With Quote
Old 08-31-2007, 02:49 PM   PM User | #7
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
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>';
?>
meshi is offline   Reply With Quote
Old 08-31-2007, 02:50 PM   PM User | #8
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
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..
Mwnciau is offline   Reply With Quote
Old 08-31-2007, 02:53 PM   PM User | #9
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
is it not need to call the function tf()..all i need to do is get the value of txt?
meshi is offline   Reply With Quote
Old 08-31-2007, 02:57 PM   PM User | #10
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
still it didnt work
meshi is offline   Reply With Quote
Old 08-31-2007, 03:10 PM   PM User | #11
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
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.
Mwnciau is offline   Reply With Quote
Old 08-31-2007, 03:58 PM   PM User | #12
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
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?
meshi is offline   Reply With Quote
Old 08-31-2007, 04:19 PM   PM User | #13
Bahamut
New Coder

 
Join Date: Aug 2007
Posts: 26
Thanks: 0
Thanked 4 Times in 4 Posts
Bahamut is an unknown quantity at this point
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>
???
Bahamut is offline   Reply With Quote
Users who have thanked Bahamut for this post:
meshi (09-06-2007)
Old 08-31-2007, 05:18 PM   PM User | #14
che_anj
Regular Coder

 
che_anj's Avatar
 
Join Date: Aug 2006
Location: Philippines
Posts: 157
Thanks: 12
Thanked 3 Times in 3 Posts
che_anj is an unknown quantity at this point
Mechelle I told you Bahamut is the best. hehehhe
che_anj is offline   Reply With Quote
Old 08-31-2007, 05:31 PM   PM User | #15
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
There's no point in using php to echo out those divs etc if js and css is controlling them
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:49 PM.


Advertisement
Log in to turn off these ads.