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 July 17th, 2004, 12:14 PM
Authorized User
 
Join Date: Feb 2004
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically Generating Textboxes

I want to design a page where user can select the number of recipients he wants send his mail to.He could be able to select that number thru a dropdown combo box.As he selects the number the textboxes should appear on the page...waiting for reply

   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
__________________
   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
 
Old July 17th, 2004, 01:02 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Greetings Maqsood,

I don't know why you posted this in PHP, unless you want to send the user back to the server every time he/she selects a new number.

This can be accomplished much more easily with JavaScript:

<script type='text/javascript'>

var divs = new array();
divs[0] = document.getElementById('a');
divs[1] = document.getElementById('b');
divs[2] = document.getElementById('c');
divs[3] = document.getElementById('d');
divs[4] = document.getElementById('e');

function showBoxes(howMany)
{

 howMany--;

 hideBoxes; //hide them all, so we can show how many we want

 for(var i = 0; i < howMany; i++)
 {
  divs[i].style.visibility = 'visible';
 }

}

function hideBoxes()
{

 for(var i = 0; i < 5; i++)
 {
  divs[i].style.visibility = "hidden";
 }

}
</script>
HOW MANY:
<select onchange='showBoxes(this.options[this.selectedIndex].text)'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<br/>
<div id='a'>
<input type='text'/>
</div>
<div id='b'>
<input type='text'/>
</div>
<div id='c'>
<input type='text'/>
</div>
<div id='d'>
<input type='text'/>
</div>
<div id='e'>
<input type='text'/>
</div>

Try it and tell me if it works.

HTH,

Snib

<><
 
Old July 18th, 2004, 04:27 AM
Authorized User
 
Join Date: Feb 2004
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you just care to comment why we shoyuld do this in Javascript(Client side) and not in PHP(Server side).
What are the advantages and disadvantages for each of these scripting languages?
Thanx for your useful suggestion...

   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
 
Old July 19th, 2004, 04:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem with sending the request back to the server every time anything happens on the page, is that it wastes time, bandwidth, and server resources. This is considered a bad idea in every web-based technology in existence, except Microsoft .NET (where it is considered a "Cool New Feature").

In essence, you cannot achieve what you are aiming to do without recourse to Javascript, anyway - since the trigger that you wish to initiate the effect is the selection of a new value from the dropdown box (i.e. a JavaScript "onchange" event). The main disadvantage of Javascrit is that it may not be enabled in the client's browser - but like I say, you'd need Javascript to even achieve what you are aiming for. In all likelihood, you'll need to have some sort of fallback mechanism in place, to make provision for users who do not have Javascript enabled.

Dan
 
Old July 19th, 2004, 04:56 PM
Authorized User
 
Join Date: Feb 2004
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Dan...thankyou very much for your justification and reasoning!

   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
 
Old March 6th, 2006, 01:05 PM
Registered User
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ggriffit
Default

This script does not work, we get an 'divs' is null or not an object error. Any reason why this would not work now?
 
Old March 9th, 2006, 09:14 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

> This [reconnecting to the server when state changes on the client] is considered a bad idea in every web-based technology in existence, except Microsoft .NET (where it is considered a "Cool New Feature").

... and AJAX . Have a look for example at the javascript on google suggest:
http://www.google.com/webhp and
http://www.google.com/ac.js

XMLHttpRequest is used to do a call to the server every time the state of the input box changes, thus allowing it to 'guess' what you're going to type next.

Whether or not this is a 'cool new feature' remains to be seen ;)

Cheers,
Charlie

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating Textboxes with the GridView Template yes_no ASP.NET 2.0 Professional 3 September 13th, 2008 07:48 AM
Dynamically generated textboxes and their values Frode ASP.NET 2.0 Basics 1 April 17th, 2006 03:46 PM
Generating html tags dynamically sachin lad Servlets 1 April 26th, 2005 05:35 PM
Dynamically displaying textboxes and label lily611 General .NET 1 December 15th, 2004 06:59 PM
Using the IDs of dynamically created textboxes mahulda ASP.NET 1.0 and 1.1 Basics 3 February 17th, 2004 05:05 AM





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