Hi,

im sort of trying to insert an array value as an argument, illustrated in the following code:

for($j=0;$j<count($number);$j++) {
<input type='text' 
size='1' 
name='inputno' 
id='inputno$j'
onchange='check_input(this.value, (i wanna get the value of $j here) )'>"; 
}

any idea?

thank you

Member Avatar for rajarajan2017

what is $number? an Array?
if it is php file then <input type....> should come within echo

hi,

yes $number is an array.

how do i pass the "$j" as an argument? or the id itself?

this is my another portion of the code

function check_input(inputno, id) {

	// Confirm that the object is usable:
	if (ajax) { 
		ajax.open('get', 'checkinputno.php?inputno=' + inputno);
		
		// Function that handles the response:
		ajax.onreadystatechange = handle_check;
		
		// Send the request:
		ajax.send(null);

	} else { // Can't use Ajax!
		alert('The availability of this username will be confirmed upon form submission.');
	}
	
}

so as you can see, im trying to pass the id value into check_input function

option 1

<?php
for($j=0;$j<count($number);$j++) 
{
 ?>
 
 <input type='text' size='1' name='inputno<?php echo $j;?>' id='inputno<?php echo $j;?>' onchange="check_input(this.value, '<?php echo $j;?>' );">

 <?php
 }
?>

option 2

<?php
for($j=0;$j<count($number);$j++) 
{

 	echo "<input type='text' size='1' name='inputno{$j}' id='inputno{$j}' onchange=\"check_input(this.value, '{$j}')\">";

}
?>

hi thx for the effort but still it doesnt work :(

Member Avatar for rajarajan2017
<?php
$pizzaToppings = array('onion', 'tomato', 'cheese', 'anchovies', 'ham', 'pepperoni'); 
for($j = 0; $j < sizeof($pizzaToppings); $j++) {
	echo "<input type='text' size='1' name='inputno{$j}' id='inputno{$j}' onchange=\"check_input(this.value, '{$j}')\">";
}
?>
<script language="javascript">
function check_input(i, j) {
	alert(i + " " + j);
}
</script>

you view your html source and see what is going wrong

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.