0

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

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by urtrivedi
0

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

0

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}')\">";

}
?>

Edited by urtrivedi: n/a

0
<?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>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.