Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 10th, 2006, 05:30 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing javascript variable to html or php

I have a page that contains a link to, say a delete product page, and I want the user to insert the code of the product in a javascript prompt box, then passing that code entered to the second page so the code knows which product to delete. And I want it to be passed in the url, as it should be something like (delete.php?code=5) where the user inserted 5 in the prompt box.

I've tried many methods by trying to pass the value to php or to html but failed. Do any one have a good idea?

  #2 (permalink)  
Old July 12th, 2006, 05:18 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No Javascript needed:

<form method="get" action="delete.php" name="myForm">
<input type="text" name="code" value="5">
<input type="submit">
</form>

If you really wanted, though, you could replace the submit button with this to do the same thing;

<input type="button" onClick="document.location.href='delete.php?code=' + document.myForm.code.value;">

Though in situation you presented, it's best to use a submit button or an input image.

Jon Emerson
http://www.jonemerson.net/
  #3 (permalink)  
Old July 12th, 2006, 06:58 AM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It seems that you didn't get what I meen. I want the user to click a hyperlink not a submit button, then a prompt box appears waiting the user to enter the code in it, and when he do that he is taken to (delete.php?code=number) where (number) is the number he entered in the prompt box.

Any way I have found a good and simple way to do that with the following code:

Code:
<script>
function get_code(form_name)
{
    var number = prompt("Enter code","");

    if (number != null && number != '')
    {
        document.forms[form_name].code.value = number;
        document.forms[form_name].submit();
    }
}
</script>
Code:
<FORM name="delete_product_code" METHOD="GET" ACTION="delete.php">
<INPUT name="code" value="" TYPE="hidden">
</FORM>
Code:
<a href="#" onClick="get_code('delete_product_code');">Delete Product</a>
  #4 (permalink)  
Old July 12th, 2006, 02:48 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, ok :). I'm glad you figured it out :).

Jon Emerson
http://www.jonemerson.net/


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 05:23 PM
Problem with passing variable in php 5 Joyhh Beginning PHP 1 July 14th, 2008 12:05 PM
passing php variable to perl nriv08 PHP How-To 0 March 27th, 2008 10:38 AM
Passing Parameters in html/javascript js_newbie Javascript 2 February 17th, 2007 08:44 PM
passing php variable to javascript and vice versa onmcv Beginning PHP 0 March 24th, 2005 01:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.