help with js and php needed

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 1445 Views - Last Post: 25 May 2009 - 05:47 PM

#1 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

help with js and php needed

Posted 08 May 2009 - 05:18 AM

ok so i have this little line of php code amongst a lot of other php and i want to add jome js valitation (confirm box)

if($this->ryes == 1){ echo "<form method='post' action='home.php?page=forts⊂=rsh'></form>";}echo "


my initial idea was to use something like


if($this->ryes == 1){ echo "<form method='post' action='home.php?page=forts⊂=rsh'><input type='submit'  name='totage' value='Upgrade'>"?>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("blah de blah");
if (r==true)
  {
  //continue submitting form
  }
else
  {
  dont submit
  }
}
</script><?php echo "</form>";



now i very much doubt this will work and dont know how to execute php or forms from inside js so can anyone help me with this ??

regards
Matty

Is This A Good Question/Topic? 0
  • +

Replies To: help with js and php needed

#2 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: help with js and php needed

Posted 08 May 2009 - 05:47 AM

I don't really understand where you are going, do you want to run the Javascript while the PHP process is still running or what are you saying? :)

View Postghqwerty, on 8 May, 2009 - 04:18 AM, said:

ok so i have this little line of php code amongst a lot of other php and i want to add jome js valitation (confirm box)

if($this->ryes == 1){ echo "<form method='post' action='home.php?page=forts⊂=rsh'></form>";}echo "


my initial idea was to use something like


if($this->ryes == 1){ echo "<form method='post' action='home.php?page=forts⊂=rsh'><input type='submit'  name='totage' value='Upgrade'>"?>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("blah de blah");
if (r==true)
  {
  //continue submitting form
  }
else
  {
  dont submit
  }
}
</script><?php echo "</form>";



now i very much doubt this will work and dont know how to execute php or forms from inside js so can anyone help me with this ??

regards
Matty

Was This Post Helpful? 0
  • +
  • -

#3 roudard  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 143
  • Joined: 26-September 05

Re: help with js and php needed

Posted 08 May 2009 - 06:15 AM

you could remplace the submit by a button with an behaviour set onclick of this button
<form id='myForm' ...> ...
<input type=button onclick=show_confirm() value='submit' >



and then

function show_confirm()
{
var form = document.getElementById('myForm');
if (confirm("blah de blah"))
  {
  form.submit();
  }
else
  {
  return false
  }
}



hope this helps

This post has been edited by roudard: 08 May 2009 - 06:16 AM

Was This Post Helpful? 0
  • +
  • -

#4 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: help with js and php needed

Posted 08 May 2009 - 03:15 PM

thanks i think that is what i want, wimpy i think roudard got it right but what i wanted was to make sure the user confirmed what they were doning before the form was submitted :) thanks
Was This Post Helpful? 0
  • +
  • -

#5 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: help with js and php needed

Posted 08 May 2009 - 03:56 PM

Then he is absolutely right! :)

View Postghqwerty, on 8 May, 2009 - 02:15 PM, said:

thanks i think that is what i want, wimpy i think roudard got it right but what i wanted was to make sure the user confirmed what they were doning before the form was submitted :) thanks

Was This Post Helpful? 0
  • +
  • -

#6 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: help with js and php needed

Posted 09 May 2009 - 09:23 AM

opk so i have that but whenever i click the ok button on the confirm it doesnt seem to reload the page or anything which i thought it should. also i dont get any info from the post data or at least i cant find it
Was This Post Helpful? 0
  • +
  • -

#7 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: help with js and php needed

Posted 09 May 2009 - 12:07 PM

Can you post the entire javascript ? and the html code for the entire form ?

Did you set the id-attribute onto the form-tag in the html code? :)

View Postghqwerty, on 9 May, 2009 - 08:23 AM, said:

opk so i have that but whenever i click the ok button on the confirm it doesnt seem to reload the page or anything which i thought it should. also i dont get any info from the post data or at least i cant find it

Was This Post Helpful? 0
  • +
  • -

#8 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: help with js and php needed

Posted 09 May 2009 - 12:21 PM

the html line of code,

	";if($this->ryes == 0){ echo "<form id='myform' method='post' action='home.php?page=forts&sub=rsh'><input type='button' name='upgrade' onclick=show_confirm() value='Upgrade'></form>";}echo "&nbsp;
i have made it so that ryes = 0 for the time being but it depends on other stuff and it should be 1 but that shouldnt make a differance

here is the js
<script type='text/javascript'>
var currentTime = new Date()
var hours = currentTime.getHours()-6
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()
if (minutes < 10){
minutes = "0" + minutes
}
if(seconds < 10){
seconds = "0" + seconds
}

function show_confirm()
{
var form = document.getElementById('myform');
if (confirm("When you research a new tech age half your troops will not survive the transformation. Not only this but all your troops will cost significantly more to buy."))
  {
  form.submit();
  }
else
  {
  return false
  }
}

</script>


thanks
Was This Post Helpful? 0
  • +
  • -

#9 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: help with js and php needed

Posted 09 May 2009 - 12:56 PM

Well, the javascript looks fine, only looked at it quick though, but the HTML is a little off (I think) try this:
"; if($this->ryes == 0) { echo '<form id="myform" method="post" action="home.php?page=forts⊂=rsh"><input type="button" name="upgrade" onclick="show_confirm()" value="Upgrade"></form>'; } echo "


Hope it fixes it! :)

View Postghqwerty, on 9 May, 2009 - 11:21 AM, said:

the html line of code,

	";if($this->ryes == 0){ echo "<form id='myform' method='post' action='home.php?page=forts⊂=rsh'><input type='button' name='upgrade' onclick=show_confirm() value='Upgrade'></form>";}echo "
i have made it so that ryes = 0 for the time being but it depends on other stuff and it should be 1 but that shouldnt make a differance

here is the js
<script type='text/javascript'>
var currentTime = new Date()
var hours = currentTime.getHours()-6
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()
if (minutes < 10){
minutes = "0" + minutes
}
if(seconds < 10){
seconds = "0" + seconds
}

function show_confirm()
{
var form = document.getElementById('myform');
if (confirm("When you research a new tech age half your troops will not survive the transformation. Not only this but all your troops will cost significantly more to buy."))
  {
  form.submit();
  }
else
  {
  return false
  }
}

</script>


thanks

Was This Post Helpful? 0
  • +
  • -

#10 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: help with js and php needed

Posted 10 May 2009 - 02:01 AM

thats just the reverse of what ive got, its wierd because i end an echo string before the if it should look like this

if($this->ryes == 0){ echo "<form id='myform' method='post' action='home.php?page=forts&sub=rsh'><input type='button' name='upgrade' onclick=show_confirm() value='Upgrade'></form>";}echo " 


oh and how come my &sub showed as the funny c thing on here ??
Was This Post Helpful? 0
  • +
  • -

#11 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: help with js and php needed

Posted 10 May 2009 - 05:34 AM

&sub; == a html entity... try &amp;sub

I don't actually know if it is of big importance but I think that you should put your html attribute values inside double quotes: attribute="value" and not single quotes: attribute='value'. The one thing I especially noticed was that you omitted the quotes around the onclick attribute's value: onclick=show_confirm() when it, in my opinion, should be: onclick="show_confirm()".

Hope it helps! :)
Was This Post Helpful? 0
  • +
  • -

#12 roudard  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 143
  • Joined: 26-September 05

Re: help with js and php needed

Posted 10 May 2009 - 10:57 AM

Check the page source to see what php actually outputs... with a long string like this it's easy to make a typo or forget to open/close a quote or something like this ...

View Postghqwerty, on 10 May, 2009 - 01:01 AM, said:

thats just the reverse of what ive got, its wierd because i end an echo string before the if it should look like this

if($this->ryes == 0){ echo "<form id='myform' method='post' action='home.php?page=forts&sub=rsh'><input type='button' name='upgrade' onclick=show_confirm() value='Upgrade'></form>";}echo " 


oh and how come my &sub showed as the funny c thing on here ??

Was This Post Helpful? 0
  • +
  • -

#13 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: help with js and php needed

Posted 16 May 2009 - 03:52 AM

sorry for ther delay.

this is the source
<form id='myform' method='post' action='home.php?page=forts&sub=rsh'><input type='button' name='upgrade' onclick=show_confirm() value='Upgrade'></form>&nbsp;


i even tried name='myform' but no succes.

any help ?
Was This Post Helpful? 0
  • +
  • -

#14 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: help with js and php needed

Posted 16 May 2009 - 05:05 AM

onclick=show_confirm() ----> onclick="show_confirm()" ...


View Postghqwerty, on 16 May, 2009 - 12:52 PM, said:

sorry for ther delay.

this is the source
<form id='myform' method='post' action='home.php?page=forts&sub=rsh'><input type='button' name='upgrade' onclick=show_confirm() value='Upgrade'></form>&nbsp;


i even tried name='myform' but no succes.

any help ?

Was This Post Helpful? 0
  • +
  • -

#15 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: help with js and php needed

Posted 16 May 2009 - 06:22 AM

wil try that ut how can that be the problem when i still get the confirm box ???
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2