TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   many input boxes that the user selects (http://www.talkphp.com/javascript-ajax-e4x/3482-many-input-boxes-user-selects.html)

webtuto 10-16-2008 02:15 AM

many input boxes that the user selects
 
hey
i want to give the visitor the ability to write in a TEXT FIELD the number of TEXT FIELDS he wants to generate
thanks

Wildhoney 10-16-2008 11:45 AM

1 Attachment(s)
You can do either PHP way, which requires the page to reload, or the JavaScript way, which doesn't. I have shown you the PHP method below, as this is the easiest way, and the best way to understand how to do it:

html4strict Code:
<form enctype="multipart/form-data" method="post">

    How many text boxes shall we show?
    <input type="text" name="iTextboxes" value="<?php echo (int) @$_POST['iTextboxes']; ?>" />
    <input type="submit" value="Generate Textboxes" />
   
</form>

php Code:
<?php if (isset($_POST['iTextboxes'])): ?>

    <?php for ($iIndex = 0; $iIndex < (int) $_POST['iTextboxes']; $iIndex++): ?>
        <input type="text" name="szTextbox[]" /><br />
    <?php endfor; ?>

<?php endif; ?>

webtuto 10-17-2008 05:35 PM

thanks :d
.....

Wildhoney 10-17-2008 11:06 PM

1 Attachment(s)
Sorry, I didn't see that this thread was specifically in the JavaScript forum. I have amended the script and added JavaScript capabilities. However, it's always good practice to have both methods in for if the user has JavaScript disabled, or perhaps unsupported by an ancient browser.

Take a look at the code and see what you think. Although, if you're new to this way of doing things, I would stick to the PHP approach as organising JavaScript files is a whole new arena. I was that silly once, and whilst I don't regret it because I learnt well from it, it's not something I'd recommend people repeat. There are better ways to learn, and that is through organising only HTML, CSS and PHP files, at the moment, then slowly progressing to other types of files such as JavaScript. The gradual approach, I feel, is far better.


All times are GMT. The time now is 10:33 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0