johnhb Posted November 27, 2008 Share Posted November 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/134444-access-a-php-array-from-input-namexyz/ Share on other sites More sharing options...
DeanWhitehouse Posted November 27, 2008 Share Posted November 27, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/134444-access-a-php-array-from-input-namexyz/#findComment-699961 Share on other sites More sharing options...
ratcateme Posted November 27, 2008 Share Posted November 27, 2008 also you missed the $ out of the first echo echo "<input type=\"text\" name=\"mybid_rate[$j]\" size=\"5\" />"; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/134444-access-a-php-array-from-input-namexyz/#findComment-699963 Share on other sites More sharing options...
johnhb Posted November 27, 2008 Author Share Posted November 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/134444-access-a-php-array-from-input-namexyz/#findComment-700095 Share on other sites More sharing options...
DeanWhitehouse Posted November 27, 2008 Share Posted November 27, 2008 View the source code and check that the php is writing it correctly. Quote Link to comment https://forums.phpfreaks.com/topic/134444-access-a-php-array-from-input-namexyz/#findComment-700442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.