This topic is locked

Javascript question

6/9/2007 8:53:31 AM
PHPRunner General questions
M
michaelmac author

Hey Everyone..
I am not sure how to do this. What I want to do is click on a link on _list.php to ask the user to enter a var in Javascript, then pass this var to a .php event (like print or export). I can not find anything here if anyone has done this.
As always
Thanks in advance
Mike

M
michaelmac author 6/10/2007

Hey Everyone..

I am not sure how to do this. What I want to do is click on a link on _list.php to ask the user to enter a var in Javascript, then pass this var to a .php event (like print or export). I can not find anything here if anyone has done this.
As always
Thanks in advance
Mike


Hey Everyone
I was able to insert this javascript code with the Visual Editor:
<input type=button value="Renew Titles"

onClick="f=prompt('Enter PO Number','po');

alert('PO Number: '+f+'!')">
But now I am stuck.. how do I pass the variable 'f' to a .php page?
Thanks
Mike

Sergey Kornilov admin 6/10/2007

Mike,
here is how you can make it work.

  1. Add a hidden field to the frmAdmin form
    <input type=hidden value="" name="po_number">
  2. Modify javascript code:
    <input type=button value="Renew Titles"

    onClick="f=prompt('Enter PO Number','po'); document.forms.frmAdmin.po_number.value=f;

    frmAdmin.submit();" >
  3. On the page where you process form submission you can access this value as $_POST["po_number"]

M
michaelmac author 6/11/2007

Mike,

here is how you can make it work.

  1. Add a hidden field to the frmAdmin form
    <input type=hidden value="" name="po_number">
  2. Modify javascript code:
    <input type=button value="Renew Titles"

    onClick="f=prompt('Enter PO Number','po'); document.forms.frmAdmin.po_number.value=f;

    frmAdmin.submit();" >
  3. On the page where you process form submission you can access this value as $_POST["po_number"]


Thanks Sergey
I am trying to use your code more like what Jane showed me to "process selected". What I am trying to do is pass po_number along with the "selected" items on the page. I do not need to use a "button", a <A>href=</A> would work also. I mean is this looking more what I should do:
<input type=hidden value="" name="po_number">
<INPUT onclick="f=prompt('Enter PO Number','');
document.forms.frmAdmin.po_number.value=f;
frmAdmin.submit(); return false;
type=button value="Renew Titles" href="renewals_list.htm#">

<!-- delete form -->
What I want to do is send the po_number to a _list.php page to process, or will I have to rework this code some more.
Thanks in advance for all your help. I am learning more and more the POWER and VERSATILITY of this tool, and I love it.. please keep all the good work..
Mike

Sergey Kornilov admin 6/11/2007

Mike,
I miss the question.

M
michaelmac author 6/11/2007

Mike,

I miss the question.


Hey Sergey
I am sorry. I guess early in the AM I a bit foggy. This is my snippet in my renewals_list page. Will it prompt send the value stored in the object.f to say "Before delete" event.. ? I am trying to see if it is being redirected to the href tag?
Thanks
Mike
<input type=hidden value="" name="po_number">
<INPUT onclick="f=prompt('Enter PO Number','');
document.forms.frmAdmin.po_number.value=f;
frmAdmin.submit(); return false;
type=button value="Renew Titles" href="renewals_list.htm#">

<!-- delete form -->

Sergey Kornilov admin 6/11/2007

Mike,
no, this code won't send anything to BeforeDelete event.

M
michaelmac author 6/11/2007

Mike,

no, this code won't send anything to BeforeDelete event.


Hey Sergey,
Is there another approach you could suggest as a way I can pass the 'po' to an event?
Thanks
Mike

M
michaelmac author 6/11/2007



Hey Sergey,
Is there another approach you could suggest as a way I can pass the 'po' to an event?
Thanks
Mike


Hey Sergey,
I am sorry. I am still thinking from one side,not the client-server model. Javascript runs on the client side, php-mysql on the server side. I understand now, forgive my ignorance. I redid the code again:
<input type=button value="Enter PO" name="po_number"

onClick="f=prompt('Enter PO Number','po');

document.forms.frmAdmin.po_number.value=f;

frmAdmin.submit();" >
I believe the po is stored as a value $_POST["po_number"] on the client side. When I chose something like "Delete Selected" and BeforeDelete event, should I be able to see the $_POST["po_number"]? I looked for it, but I am not sure how to test for it. When I did a print_r($_POST), I saw nothing but the array I had selected to delete, did my code not store it when I did the submit with my code above..
Thanks for your patience, I am starting to grasp the concepts now... HTML and Javascript are on one side.. the meat of driving the page is PHP and mySQL.
Thanks so very much.. I hope you can tell me what I am doing wrong...
Mike

Sergey Kornilov admin 6/11/2007

Mike,
to pass something to BeforeDelete event user needs to click "Delete Selected" link.

This means you need to add this Javascript code to "Delete selected" link and, probably, rename this link.