5 Replies - 1657 Views - Last Post: 02 April 2011 - 01:06 PM

#1 newbieHQ  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 20-January 11

passing php id/name to javascript

Posted 02 April 2011 - 04:05 AM

hi everyone....

below is my code to perform confirmation box for user to proceed or not...but somehow i encounter a problem where i cant passing my sale_id to another page by using window.location here ... it return the blank page for me because sale_id cant passed to other page... my action is empty (action="") because it return to the same page and trying to proceed to javascript confirmation there and proceed to another page if the user press ok button ... but somehow i cant send the sale_id to another page...can someone help me here? thank you so much ?
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Are You Sure You Wan To Proceed?");
if (r==true)
  {
 window.location='./index.php?todo=updatesale&sale_id=<?php echo $row['sale_id']?>';
  }
  else
 window.location='./index.php?todo=ms';
}
</script>



below is my php form ..
<form name="updatesale" id="updatesale" method="post" action="">
<td style="width: 30px"><input type="button" id="button1" value="Update" onclick="show_confirm()" /></td>
<input type="hidden" id="sale_id"name="sale_id" value="<?php echo $row['sale_id']; ?>" />
</form>




thanks everyone ... :)

This post has been edited by newbieHQ: 02 April 2011 - 04:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: passing php id/name to javascript

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: passing php id/name to javascript

Posted 02 April 2011 - 05:45 AM

if you want to use the same page, you will have to supply an id to the action like so:
action ='?id=some_id'


If you want to sent the value (which is $row['sale_id']) you can pass the form to the javascript function like:
onclick="show_confirm(this)"

Declare the javascript function like:
function show_confirm(form){
...


refer to the value of this form like:
var sale_id = form.sale_id.val();
window.location="./index.php?todo=updatesale&sale_id=" + sale_id;

Was This Post Helpful? 0
  • +
  • -

#3 newbieHQ  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 20-January 11

Re: passing php id/name to javascript

Posted 02 April 2011 - 08:00 AM

thanks for your reply !

somehow the javascript cant run anymore... i have been trying but still cant run :(
below is the javascript that i have been modified so far.
<script type="text/javascript">
function show_confirm(updatesale)
{
var sale_id = updatesale.sale_id.val();
var r=confirm("Are You Sure You Wan To Proceed?");
if (r==true)
  {
 window.location="./index.php?todo=updatesale&sale_id=" + sale_id;
   }
  else
 window.location='./index.php?todo=ms';
}
</script>


and below is the form code ... erm..by the way ....the action is remain empty because i using window.location to pass the action to other page which is updatesale ... so it remain empty ... and the confirmation box somehow does not function anymore.. i cant even click the update to another page as well... :(
<form name="updatesale" id="updatesale" method="post" action="">
<input type="button" id="button1" value="Update" onclick="show_confirm(this);" style="width: 79px" />
<input type="hidden" name="sale_id" value="<?php echo $row['sale_id']; ?>" /></tr>
</form>



thanks again !
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: passing php id/name to javascript

Posted 02 April 2011 - 09:00 AM

line #4 looks like some half-meant jQuery (val() is the value accessor of the jQuery $() object on form fields: $(form_elem).val()).
Was This Post Helpful? 0
  • +
  • -

#5 newbieHQ  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 20-January 11

Re: passing php id/name to javascript

Posted 02 April 2011 - 09:46 AM

thanks for your reply ...

jquery ?!?

i did not plan to use any jquery on this because it is just a simple pop out confirmation box by using javascript ... if the user press ok then proceed to other page.. if user press cancel...then will stay at the same page .. thats all.....

so how to solve this problem ? i have been trying here .... :( ... omg!!!

thank you !
Was This Post Helpful? 0
  • +
  • -

#6 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: passing php id/name to javascript

Posted 02 April 2011 - 01:06 PM

Hi,

Just change the
 updatesale.sale_id.val();



to
updatesale.sale_id.value;




And that would take care of the problem, if the problem. If it still doesent work do an alert of what updatesale is, or better yet use some web dev tool like firebug to inspect the forms hidden input to see what the value is before you hit submit. Good luck :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1