Page 1 of 1

Javascript sent to form textbox

Posted: Tue Sep 26, 2006 3:31 am
by NotOnUrNelly
Hi All,

I have a line of javascript code that works from a query builder I have adopted from a colleague. Basically, the query is built in php in a popup window. THis is then added to a form element on the popup window, and the submit button is pressed.

Upon the submit button being pressed, the sql code in the text box, is sent to a text box on the opener form and the popup window is closed.

This works okay using the following javascript code

Code: Select all

function copyForm() {
   opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;

  window.close();
    return false;
}
The popup form closes and my textbox is populated with the correct value that was in the previous textbox.

What I am struggling to do now is to get the value of the text box on my original form into a variable. Im guessing that I need to submit the main page form containing the text box.

I could add a submit button, but would like to automate this by having the opener page refresh and submit the new form variable using

$qryValue = $HTTP_POST_VARS['myTextField'];

Does anybody have any idea how I can achieve this, or is there a possible workaround, by sending the query to the caller page as a URL value.

Please go easy Im a newbie.

Many Thanks
Jamie

Posted: Tue Sep 26, 2006 3:37 am
by sojos
You can submit a form with javascript:

Code: Select all

opener.document.hiddenForm.submit();

Posted: Tue Sep 26, 2006 3:55 am
by NotOnUrNelly
Many Thanks for that Sojo,

This seems to refresh the page and the url has changed to

/webcharts.php?myTextField=+ResultID+like+%27%25k%25%27

I have attempted to get this into a variable using


Code: Select all

$qryValue = $HTTP_POST_VARS['myTextField'];
 echo $qryValue;
Tis is not echoing for some reason,

I have also tried to

get the value into the opener form element

using

Code: Select all

<form name="hiddenForm" onSubmit="showsigns()">
          
    <input name="myTextField" type="text" value="<?php echo $qryValue ?>">

  </form>
This is still not appearing so I am not sure whether , thie variable is picking this up.

Any ideas if I have done everything correctly and how I can be sure the variable $qryValue contains the required value.

This is the problem when you adopt someone elses code and have a little understanding of php and non of javasctipt


Thanks
Again

Jamie

Posted: Tue Sep 26, 2006 4:10 am
by NotOnUrNelly
Sorted I should be using $HTTP_GET_VARS not $HTTP_POST_VARS

I have found another problem, the varaibel has the value

Team like \'%1%\'

How do I get it to read

Team like 1

and get rid of the \'s and Percenetages

many Thanks
Jamie

Posted: Tue Sep 26, 2006 4:34 am
by NotOnUrNelly
Sorry to keep answering my own questions, it was the way the query was structured. That added the '%'\'s.

Im not sure what they where for but it seems to be feeding the information I require back to the form.

Cheers
Jamie

Posted: Tue Sep 26, 2006 6:47 am
by sojos
If your php receives strings with \' (backslash apostroph) in it, then that's usually because magic_quotes_gpc is turned on. Use this code to get rid of it:

Code: Select all

$query = $_GET["query"];
if (get_magic_quotes_gpc()) {
    $query = stripslashes($query);
}
Best would be to turn magic quotes off in php.ini

Posted: Tue Sep 26, 2006 6:54 am
by NotOnUrNelly
Many Thanks for that Sojo and your help earlier. I'm sort of getting there with this PHP stuff