Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP 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
 
Old November 25th, 2003, 09:54 PM
Authorized User
 
Join Date: Oct 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default display return value of prompt box to php page

when the user clicked the second or third radio button, the prompt box will ask for the name. then the name is will be displayed on the text box when the ok button of the prompt box is clicked. However, I'm not able to display the value in the text box.

Please correct my code below.

<HTML>
<HEAD>
<script type="text/javascript">
function function1(){
var name = prompt("Please enter your name","")
if (name != null && name != "")
{
return name;
}
}
</script>
</HEAD>
<BODY>
<input type="radio" name="radio1" value="one" >one
<input type="radio" name="radio1" value="two" onclick="function1()">two
<input type="radio" name="radio1" value="three" onclick="function1()">three
<input type="hidden" name="hidden1" value="name">
</BODY>
</HTML>

 
Old November 26th, 2003, 02:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't see anywhere in your code where you'd display that name.

Notes:

1) function1() just returns the name entered in the checkbox.
2) function1() is ONLY called by your radio buttons onClick event, and nothing is done with the return value.


That means you're just throwing the value away -- you're not DOING anything with it.

Your hidden input field has a value of "name". That's just a string, "name". It's in no way related to the local variable you define within the scope of function1().

Perhaps you meant to do this:

function function1()
{
    var name = prompt("Please enter your name", "");
    if ((name != null) && (name != ""))
    {
        document.form1.hidden1.value = name;
    }
}


See the difference? You're actually DOING something with the value returned from the prompt box -- you're assigning the value property of the hidden1 object (which translates into the value attribute of the hidden1 element in HTML).

You need to wrap your form input elements in a <form name="form1"> tag for this to work.


You've been asking a lot of JavaScript questions lately -- remember that this is a PHP forum, so in the future you should direct your JavaScript questions to the appropriate forum -- there's several to choose from.


Take care,

Nik
http://www.bigaction.org/
 
Old November 27th, 2003, 10:49 PM
Authorized User
 
Join Date: Oct 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!it works.
Sorry for the trouble because i was new here and doesn't realize that there's a javascript forum.

 
Old December 1st, 2003, 01:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's not a problem, I just think you'll get much better answers from the JS gurus in the other forums than you will from PHP gurus who dabble in JS when it suits us. =)


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Php page doest not display anything urtrivedi Beginning PHP 2 November 9th, 2007 02:38 AM
Closing page without prompt in IE7 gp_mk ASP.NET 1.0 and 1.1 Professional 2 November 22nd, 2006 10:29 AM
Input Box return value pakman Excel VBA 1 June 15th, 2005 04:29 AM
List box in prompt box hosefo81 Javascript How-To 3 December 8th, 2003 04:18 AM





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