Jump to content

New Window - Not!


Traveller29

Recommended Posts

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,

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

 

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.