Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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?

Reply With Quote
  #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/
Reply With Quote
  #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>
Reply With Quote
  #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/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:47 AM.


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