Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 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 17th, 2004, 12:14 PM
Authorized User
 
Join Date: Feb 2004
Location: Islamabad, , Pakistan.
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
Reply With Quote
  #2 (permalink)  
Old July 17th, 2004, 01:02 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
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

<><
Reply With Quote
  #3 (permalink)  
Old July 18th, 2004, 04:27 AM
Authorized User
 
Join Date: Feb 2004
Location: Islamabad, , Pakistan.
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
Reply With Quote
  #4 (permalink)  
Old July 19th, 2004, 04:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old July 19th, 2004, 04:56 PM
Authorized User
 
Join Date: Feb 2004
Location: Islamabad, , Pakistan.
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
Reply With Quote
  #6 (permalink)  
Old March 6th, 2006, 01:05 PM
Registered User
 
Join Date: Dec 2003
Location: Batesville, Indiana, USA.
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?
Reply With Quote
  #7 (permalink)  
Old March 9th, 2006, 09:14 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
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
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
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



All times are GMT -4. The time now is 12:46 PM.


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