0

I have a really weird situation, I am calling my javascript function like this...

window.top.window.stopUpload(<? echo $result; ?>,<? echo $file_name; ?>);

Javascript function looks like this,

function stopUpload(success,filePath){
          var result = '';
          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
          }
          else {
             result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
          }
          document.getElementById('f1_upload_process').style.visibility = 'hidden';
          document.getElementById('f1_upload_form').innerHTML = result + '<input name="image_file" type="file" class="browse" /><input type="submit" name="submit_button" value="Upload"  class="browse"/>';
          document.getElementById('f1_upload_form').style.visibility = 'visible';     
           
          return true;   
    }

Above code does't execute stopUpload function.


However If I do like this,

window.top.window.stopUpload(<? echo $result; ?>);

and javascript like this,

function stopUpload(success){
          var result = '';
          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
          }
          else {
             result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
          }
          document.getElementById('f1_upload_process').style.visibility = 'hidden';
          document.getElementById('f1_upload_form').innerHTML = result + '<input name="image_file" type="file" class="browse" /><input type="submit" name="submit_button" value="Upload"  class="browse"/>';
          document.getElementById('f1_upload_form').style.visibility = 'visible';     
           
          return true;   
    }

With one one param, it works!

Question

Why it works with one param and not with 2? I have tried sending normal string like 'hello' instead of $file_name but still it does't call.

4
  • have you echo'd $file_name outside of the function to ensure there is a value? Commented May 10, 2012 at 11:57
  • Load the page in your browser and check the source. Odds are that $result or $file_name is null, in which case it would lead to bad syntax (i.e. window.top.window.stopUpload(,'hello') Commented May 10, 2012 at 11:57
  • 1
    Make sure that you escape your arguments with quotes, i.e. window.top.window.stopUpload('<? echo $result; ?>','<? echo $file_name; ?>'); Commented May 10, 2012 at 11:57
  • Thnks to all! problems solved! Very silly mistake Commented May 10, 2012 at 12:01

2 Answers 2

3

Call your function like this:

window.top.window.stopUpload(<? echo $result; ?>,'<? echo $file_name; ?>');

Hope it helps.

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

Comments

0

Try this :

window.top.window.stopUpload('<? echo $result; ?>','<? echo $file_name; ?>');

Remember, $result should not be any numerical value. User $result = '1' instead.

And change success == '1') in your if statement.

Hope it helps.

Comments

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.