Traveller29 Posted October 10, 2009 Share Posted October 10, 2009 I have a calendar.php which displays correctly 'as it says on the tin'! Problem is that when you click to move the month up/down it opens in a new window rather than just updating the current view? The code lines are: <input type='button' class='button' value=' > ' onClick='<?php echo "goLastMonth($month,$year,\"$form\",\"$field\")"; ?>'> and <input type='button' class='button' value=' > ' onClick='<?php echo "goNextMonth($month,$year,\"$form\",\"$field\")"; ?>'> How can I change them to behave as I want them to please? MTIA, Quote Link to comment Share on other sites More sharing options...
Garethp Posted October 10, 2009 Share Posted October 10, 2009 Well show us the javascript function goLastMonth and goNextMonth Quote Link to comment Share on other sites More sharing options...
Traveller29 Posted October 10, 2009 Author Share Posted October 10, 2009 Sorry, new to all this! <script language="javascript"> function goLastMonth(month,year,form,field) { // If the month is January, decrement the year. if(month == 1) { --year; month = 13; } document.location.href = 'calendar.php?month='+(month-1)+'&year='+year+'&form='+form+'&field='+field; } function goNextMonth(month,year,form,field) { // If the month is December, increment the year. if(month == 12) { ++year; month = 0; } document.location.href = 'calendar.php?month='+(month+1)+'&year='+year+'&form='+form+'&field='+field; } function sendToForm(val,field,form) { // Send back the date value to the form caller. eval("opener.document." + form + "." + field + ".value='" + val + "'"); window.close(); } </script> Quote Link to comment Share on other sites More sharing options...
colap Posted October 10, 2009 Share Posted October 10, 2009 I have a calendar.php which displays correctly 'as it says on the tin'! Problem is that when you click to move the month up/down it opens in a new window rather than just updating the current view? The code lines are: <input type='button' class='button' value=' > ' onClick='<?php echo "goLastMonth($month,$year,\"$form\",\"$field\")"; ?>'> and <input type='button' class='button' value=' > ' onClick='<?php echo "goNextMonth($month,$year,\"$form\",\"$field\")"; ?>'> How can I change them to behave as I want them to please? MTIA, Can you please post your whole code? Quote Link to comment Share on other sites More sharing options...
Garethp Posted October 10, 2009 Share Posted October 10, 2009 Change document.location.href to document.location Also, put your code in [ code ] and [ /code] tags. Plus, that will still refresh your page. If you want to display results without refreshing, you'll need to know AJAX Quote Link to comment Share on other sites More sharing options...
Traveller29 Posted October 10, 2009 Author Share Posted October 10, 2009 Change document.location.href to document.location Roger on this - done! Also, put your code in [ code ] and [ /code] tags. Plus, that will still refresh your page. If you want to display results without refreshing, you'll need to know AJAX New to this - can you just explain this a little more please - where do I put these bits?! Quote Link to comment Share on other sites More sharing options...
Garethp Posted October 10, 2009 Share Posted October 10, 2009 It's like this [ code ] <?php //This is code ?> [ /code ] Without the spaces would be <?php //This is code ?> It's just easier to read code that you post, like this <script language="javascript"> function goLastMonth(month,year,form,field) { // If the month is January, decrement the year. if(month == 1) { --year; month = 13; } document.location.href = 'calendar.php?month='+(month-1)+'&year='+year+'&form='+form+'&field='+field; } function goNextMonth(month,year,form,field) { // If the month is December, increment the year. if(month == 12) { ++year; month = 0; } document.location.href = 'calendar.php?month='+(month+1)+'&year='+year+'&form='+form+'&field='+field; } function sendToForm(val,field,form) { // Send back the date value to the form caller. eval("opener.document." + form + "." + field + ".value='" + val + "'"); window.close(); } </script> So did your problem get fixed? Quote Link to comment Share on other sites More sharing options...
colap Posted October 10, 2009 Share Posted October 10, 2009 Change document.location.href to document.location Also, put your code in [ code ] and [ /code] tags. Plus, that will still refresh your page. If you want to display results without refreshing, you'll need to know AJAX I have used both document.location.href and document.location in a web page. Both work. Quote Link to comment Share on other sites More sharing options...
Traveller29 Posted October 10, 2009 Author Share Posted October 10, 2009 OK, just removing the .href made no difference - still refreshed to a new window. Adding the [ code ] tags (both with or without spaces) either side of two occurances of <?php and ?> only succeeded in echoing them (as text) on the original page and the new window? Quote Link to comment Share on other sites More sharing options...
nicephotog Posted October 11, 2009 Share Posted October 11, 2009 Todays date is: <span id="date"></span> <input type="button" value="Get Todays Date and Time" onclick="timedate();"> <script> function timedate(){ var dt=new Date(); utdt = dt.getUTCDate(); locdat = dt.toLocaleString(); document.getElementById("date").innerHTML=" UTC:"+utdt+"<br>Locale:"+locdat+"<br>"; }//enfunc </script> Quote Link to comment Share on other sites More sharing options...
Traveller29 Posted October 11, 2009 Author Share Posted October 11, 2009 Thanks for that - how does it solve the issue with my calendar please? Quote Link to comment Share on other sites More sharing options...
nicephotog Posted October 12, 2009 Share Posted October 12, 2009 How? (Admittedly you pass arguments to your function)While not a problem (the less-than and greater-than symbols) in the PHP code <?php and > because they are stripped and used on the server. Less-than and greater-than symbols are technically a bit deadly on browsers and particularly XHTML and XML but in HTML if you truly knew your stuff one of two was vaguely legal in document syntax when not used to delimit an elements start and end. Here is your code again. <input type='button' class='button' value=' > ' onClick='<?php echo "goNextMonth($month,$year,\"$form\",\"$field\")"; ?>'> Here is my code for the input button element <input type="button" value="Get Todays Date and Time" onclick="timedate();"> The browser may only be giving trouble because of those symbols Here is an alternative with yours <input type='button' class='button' value=' > ' onClick='<?php echo "goNextMonth($month,$year,\"$form\",\"$field\")"; ?>' > You should replace this value=' > ' with this or some alike value='Month Later' and one value='Month Less' its a bit dangerous. Check your javascript functions internals in goNextMonth() and the other one you print for any window or location leftover code. If cosmetics of the element worry you put height and width in CSS or their style="" attribute. Quote Link to comment 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.