|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding | |
Quick PHP/HTML Forms question.
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||
|
First Time Build
|
Alright. So I'm writing a simple gallery script for my dad's website.
For this gallery, I have a separate form for adding images to a specific album. I'd like to have a SELECT that will allow the user to choose how many images will be added to the album. Choosing to add 3 images would "refresh" the form to have 3 upload boxes. How do I go about writing this? Is it as simple as this: ... print<<<end <select name="numImages"> <option value = 1>1</option> <option value = 2>2</option> <option value = 3>3</option> <option value = 4>4</option> <option value = 5>5</option> </select> <br> end; $i=0; while($i < $numImages) { print "<input name=\"images[]\" type=\"fill\">"; print "<br>"; } ... Something tells me that's not it. Thanks.
__________________
---Building Jillian--- Watch out, 56k. She's Finished!!! Guide: Replacing the Fan in a Tuniq Tower 120 - Another 56k killer. Guide: Removing the HDD from a WD MyBook Essential - 56k okay. Fkyx's lucky day...?
|
|||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||
|
ATI Enthusiast
|
You need JavaScript to do that code because PHP is all server-side code and won't work to dynamically change anything on the client side. I don't know enough Javascript to help you out with it, though.
__________________
|
|||||||||
|
|
|
|
#3 (permalink) | ||||||||||||||
|
Programmer
|
Quote:
First is the select input. And set attribute on the select onchange="this.form.submit();" The other form will be generated dynamically by the PHP. i.e. $numImages = $_POST['from_the_first_form']. And afther that you have to put make an iteration of the $_FILES superglobal array, in order to work with the uploaded files. But with Javascript will be better.. the only problem is that wit will be more complex/difficult to be done.
|
||||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
PC Gamer
|
look into AJAX and XMLHttpRequest
__________________
I have four words for you... DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS Five thousand, two hundred, and eighty points per day Next upgrades: 150 GB Raptor; 24" Monitor; 9800 GTX 4 SLI; Q6600; Auzentech Prelude; * Waiting on Sandy Bridge *
|
|||||||||||||
|
|
|
|
#6 (permalink) | |||||||||||||
|
Programmer
|
You people, are AJAX obsessed, aren't you?
I would use AJAX only in case of not knowing how to program in JavaScript. I was thinking of a simple solution: Code:
<script>
function generateUploadInputs(num){
inputCont = document.getElementById('uploadInputs');
inputCont.innerHTML = '';
for (var i =0; i < num; i++) inputCont.innerHTML += '<input type="file" name="images[]" />n<br />';
}
</script>
<select name="numImages" onchange="generateUploadInputs(this.options[this.selectedIndex]);">
<option value = 1>1</option>
<option value = 2>2</option>
<option value = 3>3</option>
<option value = 4>4</option>
<option value = 5>5</option>
</select>
<div id="uploadInputs">
</div>
Last edited by metala : 07-18-08 at 10:19 AM. |
|||||||||||||
|
|
|
|
|
#7 (permalink) | |||||||||||||
|
PC Gamer
|
You shouldn't rely on innerHTML. That standard has been deprecated.
Look into using the DOM (Document Object Model). With that, you create elements on the fly and it has better compatibility with most browsers. It's also easier to use with XML requests.
__________________
I have four words for you... DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS Five thousand, two hundred, and eighty points per day Next upgrades: 150 GB Raptor; 24" Monitor; 9800 GTX 4 SLI; Q6600; Auzentech Prelude; * Waiting on Sandy Bridge *
|
|||||||||||||
|
|
|
|
#8 (permalink) | ||||||||||||||||
|
Programmer
|
Quote:
Quote:
PS. I have lots of experience with the DOM, especially DOM2 Event Quote:
PS. I haven't thought another way than http://en.wikipedia.org/wiki/AXAH . EDIT43: I found it... http://www.w3schools.com/Ajax/ajax_responsexml.asp Damn it is a lot more source code than just using the innerHTML. And if you look through other ajax tutorials at w3schools you will see that they are mostle using innerHTML.
Last edited by metala : 07-20-08 at 08:02 PM. |
||||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|