|
|
 Rank: Martian Estate Agent
Joined: 9/14/2003 Posts: 3,358 Location: United Kingdom
|
I'm having a little problem getting PHP and Javascript to work together on a little project i'm working on. Here's my problem, I have a form that has to be sent to one file and it contains the fields i want to appear on a preview popup. I did use a script (Below) that wrote a tempary file, but it did not work for me as it could not load a template into the file. Can only help? The Javascript i was using that wrote tempary files looks like this <script language="JavaScript">
function preview() {
temp = document.reply.message.value;
preWindow = open("",
"preWindow"," menubar=yes, scrollbars=yes");
preWindow.document.open();
preWindow.document.write(temp);
preWindow.document.close();
};
</script>Then i done a onclick (Form Button) to send it to preview(). What i really need is a javascript that will either set a cookie or see what is in the field and post it to another page. Full On Design
|
|
 Rank: Martian Estate Agent
Joined: 9/14/2003 Posts: 3,358 Location: United Kingdom
|
If it helps i want somthing a little like swoj.com's preview button. Full On Design
|
|
 Rank: Admin
Joined: 8/26/2002 Posts: 3,467 Location: United Kingdom
|
Rather than do a POST, the forum cheats a little, it sets the content of the message textarea into a cookie and then loads the pop-up page it wants. The pop-up page then reads the preview text from the cookie.
The javascript that does this is as folows (in this case, for the pop-up spell checker)
function OpenSpellCheck() { var curCookie = "strMessagePreview=" + escape(document.PostTopic.Message.value); document.cookie = curCookie; popupWin = window.open('pop_spellcheck.asp', 'preview_page', 'scrollbars=yes,width=650,height=400') }
If your code is not working, check that you have your form named correctly, the format of the value object you are trying to reference is document.FORMNAME.FORMOBJECT.value, so make sure your form has the id 'reply' (based on your code), failing that change the form name and reference to something else to make sure that reply is not a keyword (ie. for the HTTP Reply)
If your form only has one submit button, you could try opening the window and using the TARGET parameter for the form to send the form to the pop-up window, though this would apply to all submit buttons on the form (if you can make it work with the TARGET parameter, I forget if that is possible.)
|
|
 Rank: Martian Estate Agent
Joined: 9/14/2003 Posts: 3,358 Location: United Kingdom
|
Would i need Javascript to retrive the cookie? I know how to do it with php...but when i tired it did not work amazingly. Full On Design
|
|
 Rank: Admin
Joined: 8/26/2002 Posts: 3,467 Location: United Kingdom
|
I don't think you would need to retreive the cookie with javascript, PHP should be able to reference the cookies in it's own code (they are sent with each page request). I gues the question would be whether the cookie is set before the pop-up window is opened, so make sure you set your cookie before that.
|
|
 Rank: Martian Estate Agent
Joined: 9/14/2003 Posts: 3,358 Location: United Kingdom
|
I just came up with
<script language="JavaScript" type="text/javascript">
function OpenPreview()
{
var curCookie = "strTextNewPage=" + escape(document.NewPage.text.value);
document.cookie = curCookie;
popupWin = window.open('admin.php?p=pop_preview', 'preview_page', 'scrollbars=yes,width=650,height=400')
}
</script>
<input class="button" name="Preview" value=" Preview " type="button" onclick="OpenPreview()" />
Something is wrong with that, but i'm not sure what :( I can't seem to get the thing to make a cookie. Full On Design
|
|
|
Guest |