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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.