Page 1 of 1

how to get a form field by clicking on a URL

Posted: Wed Jun 27, 2007 1:16 am
by dream2rule
http://i97.photobucket.com/albums/l202/ ... gement.jpg


In the above form, when i click onto add another file link, i want to display a new browse field.
How do i do that?

Can this be done using PHP?

Regards,
Dream2rule

feyd | We don't need a 150K image

Posted: Wed Jun 27, 2007 2:10 am
by Oren
Yes and no.
Yes: It can be done with PHP, but you'll have to reload the page.
No: Because you'll have to reload the page and chances are that's not what you wanted when you wrote this post.

You'll need JavaScript to do that without reloading the page :wink:

Posted: Wed Jun 27, 2007 5:01 am
by dream2rule
ok so how do i go about it using javascript...

Posted: Wed Jun 27, 2007 5:05 am
by Gente
Put you inputs into some <div> and add the HTML to this container. If you will have problems with this welcome to the Client Side forum :)

Posted: Thu Jun 28, 2007 12:14 am
by dream2rule
i just don't get javascript and ajax.. im a newbie in these areas.. But again i'm here to learn..

so would be glad if anyone can come up with a code to do the same!

Thanks and Regards,

url button via css

Posted: Fri Jun 29, 2007 7:51 pm
by miramardesign
The easy way is just to make a form button and then style it like it is a regular link via css. Re-color the background , take out the border etc. I don't think you can get it perfect perfect to loook like a link but pretty damn close the only noticable thing I had when I did this is that the url depressed/moved when active because its really a button.

Posted: Tue Jul 03, 2007 12:16 am
by martinco
you should have a javascript function that replaces the innerHtml attribute of a div each time the "add" button is pressed.
some thing like this:

Code: Select all

var count = 1;
function addBrowseField(containerDiv) {
          var html = "";
          var i;
          for(i = 0; i < count; i++) {
                    html += '<input type="file" name="file' + i + '">';
          }
          containerDiv.innerHtml = html;
          count++;
}
i don't know if this is the best way, but try it.
i don't know if the fields get reset after calling this function... if this happens, you sould make a backup of the values and then put them in the new inputs.

Posted: Tue Jul 03, 2007 1:39 am
by dream2rule
thanks all.. :)
I got it working!!

Posted: Tue Jul 03, 2007 6:14 am
by superdezign
martinco wrote:i don't know if this is the best way, but try it.
Yeah, the "best way" (or "proper way") is creating the elements and appending them, but the innerHTML property was the only property invented by Microsoft that actually proved useful. :P (ingenious on Microsoft's part, IMO)

It's just a matter of accessing those elements later on.

Posted: Tue Jul 03, 2007 6:48 pm
by martinco
superdezign wrote:the "best way" (or "proper way") is creating the elements and appending them
i think i understand what you say, but... can you post a script that does that?

Posted: Tue Jul 03, 2007 6:56 pm
by superdezign
martinco wrote:
superdezign wrote:the "best way" (or "proper way") is creating the elements and appending them
i think i understand what you say, but... can you post a script that does that?

Code: Select all

function addNewField(obj)
{
    if(typeof(obj) != 'Object') obj = document.getElementById(obj);

    var newField = document.createElement('input');
    newField.name = 'file[]';
    newField.type = 'file';

    obj.appendChild(newField);
}

Posted: Tue Jul 03, 2007 6:59 pm
by martinco
that's just amazing...
i'll have to try that...

Posted: Tue Jul 03, 2007 7:01 pm
by superdezign
martinco wrote:that's just amazing...
i'll have to try that...
Heh. JavaScript never ceases to amaze me.