value doesnt get carried to next page

Thread Solved

Join Date: Mar 2008
Posts: 14
Reputation: farahphp is an unknown quantity at this point 
Solved Threads: 0
farahphp's Avatar
farahphp farahphp is offline Offline
Newbie Poster

value doesnt get carried to next page

 
0
  #1
Apr 3rd, 2008
Hi
i'm trying to display a default value in a atext field then when user changes it im grabbing it in javascript and passing it as a hidden variable but it doesnt work

  1. //javascript function
  2. function save()
  3. {
  4. var imp = document.getElementById('yesno').checked;
  5. document.getElementById("schdate").value = document.getElementById('nextsch').value;
  6. if(imp == false)
  7. {
  8. <? $impt = 'N' ?>
  9. }
  10. else{
  11. <? $impt = 'Y' ?>
  12. }
  13. alert ("date"+document.getElementById('schdate').value)
  14. //when i alert it had value
  15. }
  16. //form
  17. <form name="mainform" method="post" action="savesupdet.php?impt=<?= $impt ?>">
  18. <td align='center' width='100'>
  19. <input type='text' id='nextsch' name='nextsch' value='<?= $nextsch?>'>&nbsp; </input> </td>
  20. <input type=hidden name=schdate id=schdate value = 'null'>
  21. </table>
  22. </form>
  23. </body>
  24. </html>
  25. // savesupdet.php file
  26. $cerll = $_POST['cerll'];
  27. $nextsch = $_POST['schdate'];
  28. $ta = $_POST['txta'];
  29. $impt = $_GET['impt'];
  30. echo $nextsch;
  31. echo "<br>";
  32. echo $cerll;
  33. echo "<br>";
  34. echo $ta;
  35. echo "<br>";
  36. echo $impt;
everything else gets posted though only this is a hidden field i tried everyting else can anyone help????????
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: value doesnt get carried to next page

 
0
  #2
Apr 3rd, 2008
Where are you calling the javascript function ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 14
Reputation: farahphp is an unknown quantity at this point 
Solved Threads: 0
farahphp's Avatar
farahphp farahphp is offline Offline
Newbie Poster

Re: value doesnt get carried to next page

 
0
  #3
Apr 3rd, 2008
on the submit button
<input type="submit" value="Save" name="Save" tabindex="7" style="font-size: xx-small" onclick="save()">
inside the form
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: value doesnt get carried to next page

 
0
  #4
Apr 3rd, 2008
  1. <?php
  2. print_r($_POST);
  3. ?>
  4. <html>
  5. <head>
  6. <script type="text/javascript">
  7. function save()
  8. {
  9. document.getElementById("schdate").value = document.getElementById('nextsch').value;
  10. alert ("date"+document.getElementById('schdate').value);
  11. //when i alert it had value
  12. }
  13. </script>
  14. </head>
  15. <form name="mainform" method="post" action="1.php?impt=<?= $impt ?>">
  16. <table>
  17. <tr>
  18. <td align='center' width='100'>
  19. <input type='text' id='nextsch' name='nextsch'>&nbsp;</td>
  20. <input type=hidden name=schdate id=schdate>
  21. </tr></table>
  22. <input type="submit" value="Save" name="Save" tabindex="7" style="font-size: xx-small" onclick="save();">
  23. </form>
  24. </body>
  25. </html>
Check this..
var imp = document.getElementById('yesno').checked;
var imp will always be true with this. You can use if condition or document.getElementById('yesno').value;
Remove value='null'.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 129
Reputation: hacker9801 is on a distinguished road 
Solved Threads: 15
hacker9801 hacker9801 is offline Offline
Junior Poster

Re: value doesnt get carried to next page

 
0
  #5
Apr 4th, 2008
and you can't set php variables from within JS. your code sets $impt to 'Y'.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 14
Reputation: farahphp is an unknown quantity at this point 
Solved Threads: 0
farahphp's Avatar
farahphp farahphp is offline Offline
Newbie Poster

Re: value doesnt get carried to next page

 
0
  #6
Apr 4th, 2008
how do i assign javascript variable to php variable?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC