Jump to content

access a php array from input name="xyz"


johnhb

Recommended Posts

I have the following code on a page:

<?php

for($j=0;$j<$n;$j++)

{

echo "<input type=\"text\" name=\"mybid_rate[j]\" size=\"5\" />";

}

?>

 

I want to access the mybid_rate array in a javascript function such as

 

    var mybid=new Array();

    <?php

    foreach($mybid_rate as $br=> $brate)

    {

    print "mybid.push(\"$brate\");";

    }

    ?>

 

I am not able to work out how to get the values from the input mybid_rate[] to the js function.

Hope someone can help me out here, please.

 

 

Link to comment
https://forums.phpfreaks.com/topic/134444-access-a-php-array-from-input-namexyz/
Share on other sites

I have the following code on a page:
<?php
for($j=0;$j<$n;$j++)
{
echo "<input type=\"text\" name=\"mybid_rate[j]\" size=\"5\" />";
}
?>
<script>
    var mybid=new Array(
    <?php
    foreach($mybid_rate as $br=> $brate)
    {
    print "'mybid.push(\"$brate\");',";
    }
    ?>);
</script>

or something

Thanks Blade280891,

I did what you suggested but I now cannot get the function val() to respond.

Here's my current code:

< script language="javascript">

function CheckData()

{

var z=bidfrm.num_bids.value;

var mybid=new Array();

<?php

foreach($mybid_rate as $br=> $brate)

{

print "'mybid.push(\"$brate\");',";

}

?>

var l=mybid[3];

if(z >0)

{

alert("Please select the number of bids you want to place "+z+l);

document.bidfrm.num_bids.focus();

return false;

};

if (mybid.count >0)

{

alert("No value for bid "+br);

document.bidfrm.bid_rate.focus();

return false;

};

 

var m= bidfrm.max_price.value;

var flag=0;

for(i=0;i<mybid;i++)

{

if(mybid>m)

{

flag=1;

}

};

 

if(flag>=0)

{

alert("Bidding Price should be lower than max price");

return false;

}

else

{

return true;

};

    document.bidfrm.submit() ;

  //return true;

};

 

function val()

{

var p=bidfrm.num_bids.value;

window.location="make_bid.php?bid_id=<?=$bid_id;?>&a="+p;

};

//-->

</script>

 

I also corrected the line

echo "<input type=\"text\" name=\"mybid_rate[$j]\" size=\"5\" />";

 

Any further thoughts, please.

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.