Jump to content

Help inserting text to parent window from pop up window


Zinnia-Aster
 Share

Recommended Posts

Hey there you guys.I'm still trying to learn javascript, and having trouble.What I've got is a text field, and below the text field is some emoticons. When I click on the emotes it inserts the code for them into the text field.But what I want to do is have a link to a pop up window, and inside thepop up window would be a list of emoticons. When you click on the emoticonsit should add the code for it to the parent window.I've been looking all over the internet for how to do this and have come upempty handed. I could really use some help.I'd like it to be just like making a new thread here on W3Schools. Emote Pop up PageCan anybody assist me in creating this? I would hugely appreciate it. :)

Link to comment
Share on other sites

  • 3 years later...

I have a similar question, but not quite the same.

 

When a user clicks on a Submit button, for a different function, it checks to see of the user is authorized to access those specific buttons.

 

If the user has the authorization, a popup window should automatically open, requesting that he enter some appropriate information.

 

This information needs to be stored in a variable, which will then be passed to the parent script.

 

When the user is done entering the information, the action continues.

 

The issue I'm having right now, is that the popup window is opening, but the parent program is not waiting for the javascript input.

 

The parent program just continues on its merry way, without the text that was supposed to be included.

 

All of the example code that I've seen requires an "onclick" statement, which I believe should not be required, as a "Submit" button has already been issued.

 

How do I get the parent program to wait for the javascript popup window entry?

 

JCF

Link to comment
Share on other sites

JustSomeGuy,

 

Thanks for the referral, but after spending several hours of research, I'm still no closer to getting the script to wait for input.

 

Here's what I've tried so far:

 

1)

 

?>

<script>

{

$REPRNOTES = prompt("Please enter any appropriate reprocessing request notes")

}

</script>

<?php

 

2)

 

echo '<script type="text/javascript">

{

$REPRNOTES = prompt("Please enter any appropriate reprocessing request notes");

}

</script>';

 

3)

 

$REPRNOTES = "readline ( string $prompt('Please enter any appropriate request notes'))";

 

4)

 

$REPRNOTES = "?> <script> prompt('Please enter any appropriate request notes'); </script> <?php";

 

5)

 

$noteprompt = "Please enter any appropriate request notes";

$REPRNOTES = readline ("?> <script>

{

prompt('$noteprompt');

}

</script> <?php");

 

I get the popup with 2 of them, but the script just continues, without waiting for the input.

 

I am relatively new to PHP and webpage development, and this one is kicking my butt.

 

Note1, I began looking at the "readline" command, after JustSomeGuys suggestion.

 

Note2, This code is only supposed to execute, if a certain condition is met.

 

I am trying to execute this code, all within a single PHP script. Aside from this one single popup window, I am not calling any other external scripts or functions.

 

Everything else is working as intended.

 

I would greatly appreciate it, if anyone could tweak one of the above examples, or if something completely different is needed, that they give the exact syntax, along with a similar example.

 

Thanks in advance,

 

JCF

Link to comment
Share on other sites

Ok, I am a little closer to my goal...

 

Here's what I've come up with so far:

 

I define a function:

 

function ReprPopupWindow()

{

?>

<script> type="text/javascript">

$REPRNOTES - prompt("Please enter any appropriate reprocessing request notes")

</script>

<?php

}

 

Then, I call the function inside of my code using the following line:

 

ReprPopupWindow()

 

This causes the popup window to appear, and it also stops the parent script from refreshing the page. Essentially, the parent script is waiting for input, just as I want it to.

 

However, using this exact code, the variable is not being initialized.

 

I need the variable "$REPRNOTES" to be populated with the text entered in the popup box.

 

Any help would be greatly appreciated.

 

Thanks in advance,

 

Joe

Link to comment
Share on other sites

That is why I asked for help!

 

Unfortunately, I am too junior to understand your very vague answers.

 

If you really want to help, I'll need some examples of what I should do. Telling me that I need to use Ajax, or that I need to use a callback, has not helped me at all.

 

The code that I posted above gives me a popup window, and it allows me to populate that window. The only thing it is not doing is populating the environment variable.

 

If you could tell me what I need to make that work, without needing to press another button, but instead triggering the popup window after a certain logical condition has been met, that is what I need.

 

If you can give me some examples of code that will do what I want, that would be much better, as I have not been able to find anything close to what I am trying to do, in any of the pages I've found so far.

 

Or, if I did find something that would do what I need, I did not understand it, or recognize it for what it was.

 

JCF

Edited by jxfish2
Link to comment
Share on other sites

Using an "if / else" conditional statement, when a certain condition is met, I want to display a popup window that prompts the user to enter some appropriate text.

 

Once the text has been entered, I simply want the code behind the popup window to populate an environment variable, that will carry forward, throughout the remainder of the backend PHP code.

 

I would have thought that was very simple to do, but I have not found any code to do that, without using an "onclick" function, or some other similar function...

 

In my current code, I can not use an "onclick" trigger to execute the function.

 

Any help would be greatly appreciated.

 

JCF

Link to comment
Share on other sites

I'm happy to point you in the right direction, but I am not here to hold anyone's hand. At the end of the day your education is your responsibility, not mine. If you search for just "callback", for example, the first page of results has a link to a Wikipedia article about the concept, and links to information specific to PHP and jQuery (i.e., Javascript). If you search for something more specific, like "Javascript callback", the first 3 results are articles explaining what they are and how to use them. If you're looking for a piece of code that exactly matches your situation that you can just copy and paste and use, you aren't going to find it (and I'm not going to write it for you). You need to understand the concepts that you're using so that you can design what you need on your own. That's what being a programmer is about, whether you are new or experienced. Having you use things that you don't understand is not going to help you. Likewise, searching for only the term "ajax" without any other qualifiers brings up 6 results in the top 10 that relate to the Javascript technology (as opposed to the Greek hero, or the household cleaner).It also sounds like you need to understand the roles that PHP and Javascript each play, because they are completely different. Again, I would encourage you to research both of them. In a nutshell, PHP runs on the server, and Javascript runs in the browser. They do not share memory space or disk or database resources or anything like that, because they are running on 2 different computers. Your computer does not execute PHP code, and the web server does not execute Javascript code. They also execute at different times. Your browser sends a request to the server, the server invokes PHP and gives it the PHP code to execute, PHP executes the code and sends the output back to the web server, the web server sends the output to your browser, and then your browser renders the HTML and executes the Javascript. PHP is long gone on the server before your browser even starts with the Javascript code.If you want PHP and Javascript to exchange information then there are several ways to do that. I would stay away from the term "environment variable" though, that is typically a variable that is managed by the operating system (e.g. the path to the Java compiler, or the path to the Windows installation directory). In PHP you're probably thinking of a session variable, which retains a value across multiple requests. If you haven't used sessions in PHP, you need to research that.PHP can give data to Javascript because you can use PHP to output Javascript code, the same way you would output HTML code. If you have a variable that contains a number, and you want to make that number available to Javascript on the page, you can use PHP to output that code, e.g.:

<?php$num = 100;?><script type="text/javascript">var num = <?php echo $num; ?>;alert(num);</script>
That is one-directional from PHP to Javascript. PHP will execute, it will produce that Javascript code and substitute the value for the $num variable, the server will send that code to your browser, and your browser will execute the code that will have the numeric value from PHP. There's no actual connection between Javascript and PHP though, you're just using PHP to create Javascript code. The output of that PHP script is this:
<script type="text/javascript">var num = 100;alert(num);</script>
Notice there is no PHP code there. It is exactly the same as if you wrote that Javascript by hand, except you used PHP to fill in the value. That is PHP effectively sending data to Javascript.If you want 2-way communication, or if you want to use Javascript to send data to PHP, then you use ajax. You need to research it, but ajax is how you use Javascript to send a request to the server. You can have some values in Javascript, and you can create a request to a PHP page where you send those values to PHP, and PHP will access them inside $_GET or $_POST, depending on how you created the request. PHP can't tell that this is an ajax request versus a "normal" request, it's just another request. PHP can also respond to an ajax request just like it responds to any other request, so you can have PHP output whatever values you want to send back to Javascript. If you want PHP to save the values that it got from Javascript in the session, so that those are available in later page requests, you can do that too as long as you're using the session correctly. The W3schools site has tutorials on all of these things, and there is plenty of other information online. Many, many people use this, and there is a ton of discussion about all of it.
Link to comment
Share on other sites

Ok, I have reached a point where I need some help, and pointing me to reference documents is not helping anymore, because of the way my code is written.

 

Here is what I have so far:

 

function getReprNotes() {

?>

<script>

var NOTE = prompt('Please enter any appropriate reprocessing request notes');

alert(NOTE);

</script>

<?php

 

getReprNotes()

 

Note that the above code is generating the prompt popup window.

 

Note that the above code is populating the HTML "NOTE" variable.

 

Note that the above code is causing the parent page to wait for the popup input.

 

But, I can not figure out how to get the HTML "NOTE" variable, back into the PHP code...

 

I need to convert the HTML variable "NOTE" to a PHP variable!

 

But, in this particular code, I am not using an "onclick" button, or a submit button...

 

How do I pass this HTML variable back to the parent PHP process?

Link to comment
Share on other sites

You send an ajax request to PHP with the value of that variable, inside the same function. Remove the alert and add an ajax request. If you don't know anything about ajax then start here:http://www.w3schools.com/ajax/default.aspThere are examples for sending both get and post requests here:http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

Link to comment
Share on other sites

just point out, NOTE is a Javascript variable. HTML (and for that matter CSS) is not a programming language per se.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...