Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Logistical problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Logistical problem

Postby brownie124 » Sat Jun 07, 2003 6:54 pm

Hi,

I understand about when JavaScript is processed and when PHP code is processed. It leaves me with a logisical problem that for some reason I can't figure out. I have "onclick" event JS code that I want to execute. That is no problem. However, I need to access a value in a PHP array and possibly set a session variable after the click and before the onclick event fires. How do I accomplish that?

Thanks,
- Brownie
brownie124
New php-forum User
New php-forum User
 
Posts: 23
Joined: Thu Feb 13, 2003 1:58 pm
Location: Peterborough, NH

Re: Logistical problem

Postby WiZARD » Sun Jun 08, 2003 2:59 am

brownie124 wrote:Hi,

I understand about when JavaScript is processed and when PHP code is processed. It leaves me with a logisical problem that for some reason I can't figure out. I have "onclick" event JS code that I want to execute. That is no problem. However, I need to access a value in a PHP array and possibly set a session variable after the click and before the onclick event fires. How do I accomplish that?

Thanks,
- Brownie

Hi!
you may just set variables do like that:
name of youre variable is some_name[some_array_name]="var_value"
in next page, in PHP you get variable $some_name[some_array_name] = var_value
understand?
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Hmmm?

Postby brownie124 » Sun Jun 08, 2003 6:09 am

I appreciate your response, but I am not following you.

when you write:
name of youre variable is some_name[some_array_name]="var_value"

Do you mean that is JavaScript code?

Thanks,
- Brownie
brownie124
New php-forum User
New php-forum User
 
Posts: 23
Joined: Thu Feb 13, 2003 1:58 pm
Location: Peterborough, NH

Postby sleepingdanny » Sun Jun 08, 2003 7:33 am

He ment => $something[car]=dog ... Just an example :P
- Its a PHP code.
sleepingdanny
New php-forum User
New php-forum User
 
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Ok but...

Postby brownie124 » Sun Jun 08, 2003 7:38 am

...maybe I am more lost than I thought. That isn't helping me. My basic problem is sharing data between JS and PHP and executing both PHP and JS code on an onclick event. I am not sure how to accomplish that and control the sequence of things between the two.

So, I am not sure how his example is guiding me.

Thanks,
- Brownie
brownie124
New php-forum User
New php-forum User
 
Posts: 23
Joined: Thu Feb 13, 2003 1:58 pm
Location: Peterborough, NH

Re: Hmmm?

Postby WiZARD » Mon Jun 09, 2003 12:05 am

brownie124 wrote:I appreciate your response, but I am not following you.

when you write:
name of youre variable is some_name[some_array_name]="var_value"

Do you mean that is JavaScript code?

Thanks,
- Brownie

yap!
first string it's in JS second in PHP
worked i'm testing....
by the way
http://www.php-forum.com/p/viewtopic.php?p=7817
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Ok

Postby brownie124 » Mon Jun 09, 2003 4:18 am

Thanks, I will try it and

Happy Birthday!
brownie124
New php-forum User
New php-forum User
 
Posts: 23
Joined: Thu Feb 13, 2003 1:58 pm
Location: Peterborough, NH

Can't get it to work

Postby brownie124 » Mon Jun 09, 2003 5:34 am

Ok Wizard, I have tried it and I can't get it to work. Here is basically what I have done. I am eliminating most of the code and just putting what I think is pertinent:


Code: Select all
<?php
    global $numsrchresults, $srchresult, $xFoo1, $HTTP_POST_VARS;

    // I am using the session variable to avoid the code the first time through.  I don't want this code executed until they do a search.

    if ($_SESSION['s_SearchFlag'] == 1)
       {
       $_SESSION['g_foo'] = $g_foo;     

       // do a lot more stuff here.
       }
    else
        $_SESSION['s_SearchFlag'] = 1;
?>

<html>
<head><title>Member Search</title></head>
<link rel="stylesheet" href="/sac/cmstyles.css" type="text/css">
<script language="JavaScript" src="/source/navbtns_sac.js"></script>
<script language="JavaScript" src="/source/utilities.js"></script>
<script language="JavaScript">

var g_foo = 0;

function init() {
    document.forms[0].txtLastOrOrg.focus();
}

function fnSubmit() {
    ++g_foo;
    document.forms[0].submit();
}

// a lot more js code here

</script>

<body bgcolor=#C0C0C0 onload="init();">
<form name="searchform" method="post" action=<?=$_SERVER["PHP_SELF"]?>>
<div id="HiddenFields">
<!--<input type=hidden name="xSubmit" value="0">-->
<input name="xNumItems" value=<?=$numsrchresults?>>
<input name="xSelected">
<input name="xFoo" value=<?=$xFoo1?>>

<table class=group2 border=0 cols=3 cellpadding=0 cellspacing=0>
   <tr>
       <td class=leftbox width=97% valign="top" align="center">
           <table width=90% cols=3 border=0>
            <tr><td colspan=3><br></td></tr>
               <tr>
                   <td class=label4 align="right" width=22%>Last/Org Name:</td>
                    <td align="left" width=55%><input id=lastororg type=text name="txtLastOrOrg" size=40 maxlength=40 title="Enter last name of individual or name of organization" tabindex=1<?=$GLOBALS['lastnameval']?>></td>
               <td align="left"><a href="#"><img NAME="tag_findbtns" src="/images/find.gif" alt="Execute search using criteria entered" border="0" onclick="fnSubmit();"></a></td>
                </tr>

      <!-- There is a lot more HTML and PHP here -->
</table>
</body>
</form>
</html>



Anyway, after I click the search button, and execute fnSubmit() you can see that I am advancing g_Foo then submitting the document then returns to the same page. I set the session variable 'g_foo' and an error gets reported to the log saying that g_foo does not exist. What am I doing wrong?

Thanks,
- Brownie
brownie124
New php-forum User
New php-forum User
 
Posts: 23
Joined: Thu Feb 13, 2003 1:58 pm
Location: Peterborough, NH

Postby Redcircle » Mon Jun 09, 2003 8:31 am

g_foo is not being posted to the sctipt. Inorder for PHP to see the variable it must be posted within the form . i.e <input type="hidden" name="g_foo">

then when you submit you must add this to your submit function

form.g_foo.value = g_foo;
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Re: Can't get it to work

Postby WiZARD » Mon Jun 09, 2003 10:48 pm

interesting for what is it?
Code: Select all
<?php
    global $numsrchresults, $srchresult, $xFoo1, $HTTP_POST_VARS;

for what you input in global $HTTP_POST_VARS :?::?::?::?:
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby brownie124 » Tue Jun 10, 2003 3:40 am

It was something that I was trying to see if it would make a difference in something else that I was noticing. I have since removed it.

By the way, I have my JS variable vs. PHP variable worked out. Thanks for the help everyone.

- Brownie
brownie124
New php-forum User
New php-forum User
 
Posts: 23
Joined: Thu Feb 13, 2003 1:58 pm
Location: Peterborough, NH

Postby WiZARD » Tue Jun 10, 2003 8:04 am

brownie124 wrote:It was something that I was trying to see if it would make a difference in something else that I was noticing. I have since removed it.

By the way, I have my JS variable vs. PHP variable worked out. Thanks for the help everyone.

- Brownie

no problem :wink:
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron