Jump to content

Does javascript support .= ?


TeddyKiller

Recommended Posts

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" />';
?>

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;
}

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;
}

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.