Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:00:53+00:00 2026-06-15T15:00:53+00:00

I have a form inside an iframe, and I’d like to prepopulate the form

  • 0

I have a form inside an iframe, and I’d like to prepopulate the form with certain data.

I’m trying to use php and javascript to accomplish this.

My code looks something like this :

   <script type="text/javascript">
      $(window).load(function() {
          document.getElementById('20988888993483').document.getElementById('input_13').value = <?=htmlspecialchars($_POST['input_13'])?>;
      }
  </script>

the id of the iframe is 20988888993483, and the ID of the input is input_13. I preload the value from previous form submission.

This code is strung together though, and I’m not quite sure what to do.

The error I get when I load the javascript is : uncaught syntaxerror unexpected end of input

UPDATE

Along with people’s suggestions, I’ve added quotes around the PHP string. In the wild, with the value being 5, the javascript looks like this — >

  <script type="text/javascript">
      $(window).load(function() {
        document.getElementById('20988888993483').document.getElementById('input_13').value = "5";
      }
  </script>

I still get the error though. Thoughts greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:00:54+00:00Added an answer on June 15, 2026 at 3:00 pm

    If the data in $_POST['input_13'] is a string (ie: not numeric or null), then you need to enclose it in quotes.

    To handle the possibility of the magic quotes configuration setting being enabled:

    $strValue = $_POST['input_13'];
    if(get_magic_quotes_gpc()) {
        $strValue = stripslashes($strValue);
    }
    

    You then need to escape double-quotes only:

    $strValue = addcslashes($strValue, '"');
    

    The string is now safe to insert into the JavaScript. Also note that there’s no need to use htmlspecialchars(), since you’re setting the value property of the element, not the innerHTML property.

    document.getElementById('20988888993483').document.getElementById('input_13').value = "<?= $strValue ?>";
    

    Edit

    Alternatively, if you’re running PHP >= 5.2.0, then the best solution is to use json_encode():

    $strValue = $_POST['input_13'];
    if(get_magic_quotes_gpc()) {
        $strValue = stripslashes($strValue);
    }
    
    document.getElementById('20988888993483').document.getElementById('input_13').value = <?= json_encode($strValue) ?>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have iframe inside my page for save data in database.I use validate.js to
I have form in my page, I am using ajax.beginform(). Inside this form I
I have file with name contact.php, inside I have form: <form method=post name=kontakt action=send_mail.php>
I have a form inside an iframe which is inside a jQuery UI dialog
I have a simple form which is inside IFRAME. When user click on SUBMIT,
I have inside a fancybox box this form: <%= simple_form_for(@message, :remote => true, :html
I have the form inside iframe, I need to set attribute before form get
I have a form inside an iframe that needs to be manipulated from the
i have a form thats inside a iframe with a input type file with
I have an iframe with a form inside a modal box and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.