0

This is what my javascript looks like:

print "<script>function newpage(){

xmlhttp=new XMLHttpRequest();

var PageToSendTo = 'select_db.php?';
var MyVariable = 'variableData';
var VariablePlaceholder = 'variableName=';
var UrlToSend = PageToSendTo + VariablePlaceholder + MyVariable + '&tweet_id='" .     $id_num;

print "xmlhttp.open('GET', UrlToSend);
xmlhttp.send();
}</script>";

(it is in a php file hence the print statement)

This is what my form submission looks like: (again in a php statement)

print "<form action=\"select_db.php\" onSubmit=\"return newpage()\">";

The function newpage is not working.. I expected the variables to be sent over in the URL but the resulting URL is just select_db.php?

help, please.

3
  • Your code has "VariablePlaceholder" twice ... is the second one supposed to be "MyVariable"? It's still not really a valid query string. Commented Jun 26, 2013 at 20:32
  • changed it.. still not working Commented Jun 26, 2013 at 20:35
  • You should use the browser console to inspect the http request and see how it's being sent to the server. Commented Jun 26, 2013 at 20:38

2 Answers 2

1

You are missing the initial <script> tag...

print "<script>function newpage(){

xmlhttp=new XMLHttpRequest();

var PageToSendTo = 'select_db.php?';
var MyVariable = 'variableData';
var VariablePlaceholder = 'variableName=';
var UrlToSend = PageToSendTo + VariablePlaceholder + VariablePlaceholder + '$tweet_id='" .     $id_num;

print "xmlhttp.open('GET', UrlToSend);
xmlhttp.send();
}</script>";

does that solve your problem ?

Sign up to request clarification or add additional context in comments.

2 Comments

It's there, just didn't include it in the code.. will edit now.
Can you say return true; as last line in your function and try ?
0

try this onSubmit=\"newpage(); return false; \"

2 Comments

It won't work to return false before calling the function, because the function will thus never be called.
@Pointy was right; I've update the solution: place function before return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.