TeddyKiller Posted May 28, 2010 Share Posted May 28, 2010 Question says it all.. I have something like.. VALUE .= 'something' in a for loop. After 5 rounds of the loop, would VALUE hold.. 'something' 5 times.. if not, how can I change it so it is like that? Quote Link to comment https://forums.phpfreaks.com/topic/203231-does-javascript-support/ Share on other sites More sharing options...
TeddyKiller Posted May 28, 2010 Author Share Posted May 28, 2010 I have this little script. Though it doesn't do anything.. it doesn't populate the div. Any help? <script> function selectMenu(VALUE) { DIV.document.getElementById('selects'); for(VAL = 0; VAL <= VALUE; VAL++) { HTML = HTML + 'Choice ' + VAL + '<input type="text" name="field"' + VAL + '" /><br />'; } DIV.innerHTML = HTML; } </script> <?php echo '<form action="" method="post"> Poll Name<input type="text" name="pollName" /> <br /> <select name="fields" onchange="selectMenu(this.value)"> <option value=""> </option>'; for($i = 1; $i < 11; $i++) { echo '<option value="' . $i . '">' . $i . '</option>'; } echo '</select> <div id="selects"></div> <input type="submit" name="submit" value="create" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/203231-does-javascript-support/#findComment-1064799 Share on other sites More sharing options...
Alex Posted May 28, 2010 Share Posted May 28, 2010 You would use += because unlike PHP where to concatenate strings you use . in JavaScript you use +. function selectMenu(VALUE) { var HTML = ''; for(var VAL = 0; VAL <= VALUE; VAL++) { HTML =+ 'Choice ' + VAL + '<input type="text" name="field"' + VAL + '" /><br />'; } document.getElementById('selects').innerHTML = HTML; } Quote Link to comment https://forums.phpfreaks.com/topic/203231-does-javascript-support/#findComment-1064809 Share on other sites More sharing options...
TeddyKiller Posted May 28, 2010 Author Share Posted May 28, 2010 Thanks.. it displays a textbox.. but.. its like this.. NaN *textbox* it doesn't display more than one.. whats the problem? Quote Link to comment https://forums.phpfreaks.com/topic/203231-does-javascript-support/#findComment-1064811 Share on other sites More sharing options...
Alex Posted May 28, 2010 Share Posted May 28, 2010 Whoops, I had a typo. You also had a problem with your HTML. function selectMenu(VALUE) { var HTML = ''; for(var VAL = 0; VAL <= VALUE; VAL++) { HTML += 'Choice ' + VAL + '<input type="text" name="field' + VAL + '" /><br />'; } document.getElementById('selects').innerHTML = HTML; } Quote Link to comment https://forums.phpfreaks.com/topic/203231-does-javascript-support/#findComment-1064815 Share on other sites More sharing options...
TeddyKiller Posted May 28, 2010 Author Share Posted May 28, 2010 Great thanks! Now.. theres a problem. If you type in some of the textboxes, change the .. drop down value.. it'll reload the inputs. I would like it so if .. someone filled in 5.. and 8 were selected.. then the user switched the drop down to 5.. it'll take off the bottom 3. Equalling 5.. without changing the values inside the 5 boxes filled. .. if you get me. <script> function selectMenu(VALUE) { var HTML = ''; HTML += '<table>'; for(var VAL = 1; VAL <= VALUE; VAL++) { HTML += '<tr><td>Choice ' + VAL + '</td><td><input type="text" name="field' + VAL + '" /></td></tr>'; } HTML += '</table>'; document.getElementById('selects').innerHTML = HTML; } </script> <style> table.td { padding:5px; } </style> <?php echo '<form action="" method="post"> <table> <tr><td>Poll Name</td><td><input type="text" name="pollName" /></td></tr> <tr><td>Number of fields</td><td><select name="fields" onchange="selectMenu(this.value)"> <option value="" selected disabled> </option>'; for($i = 1; $i < 11; $i++) { echo '<option value="' . $i . '" '; if($i == 1) { echo 'disabled'; } echo '>' . $i . '</option>'; } echo '</select></td></tr> </table> <div id="selects"></div> <table><tr><td><input type="submit" name="submit" value="create" /></td><td></td></tr></table> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/203231-does-javascript-support/#findComment-1064838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.