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 8054103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:04:26+00:00 2026-06-05T08:04:26+00:00

I have a JavaScript function within a JavaScript function. The JavaScript below inserts some

  • 0

I have a JavaScript function within a JavaScript function. The JavaScript below inserts some HTML in a div using getElementbyID.

It is passing one variable okay–that seems to be a child of an object, this.value–btw, I am a JavaScript newb, however, when I try to give it another variable to pass, the string represented by l it stops working. Below type 1 which tries to pass variable l does not work, else, does. I have also just tried putting l '+ but that did not work. Can anyone help me with proper syntax for passing variables?. Thank you.

if (type==1)
  {
  var mailbox = '<form action="mail.php" method="post"><input type="text" onkeyup="showResult(this.value,'+l+')"><input type="submit" name="submit" value="Email"><div id="livesearch"></div></form>';
  }
else
  {
  var mailbox = '<form action="share.php" method="post"><input type="text" onkeyup="showResult(this.value)"> Share<div id="livesearch"></div></form>';
  } 
document.getElementById(target).innerHTML = mailbox;
return false;
}
  • 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-05T08:04:27+00:00Added an answer on June 5, 2026 at 8:04 am

    If the string contains "Check this out." with the double quotes, this is what the resulting HTML markup would look like (with formatting added):

    <form action="mail.php" method="post">
      <input type="text" onkeyup="showResult(this.value,"Check this out.")">
      <input type="submit" name="submit" value="Email">
      <div id="livesearch"></div>
    </form>
    

    Note how the attribute value for onkeyup contains a ", which would close out the attribute, resulting in invalid HTML. If the string contains Check this out. without any quotes, the end result is still invalid, for another reason:

    <form action="mail.php" method="post">
      <input type="text" onkeyup="showResult(this.value,Check this out.)">
      <input type="submit" name="submit" value="Email">
      <div id="livesearch"></div>
    </form>
    

    In this case, showResult(this.value,Check this out.) is the event handler JavaScript, and that has a syntax error. What you want is for the string to be in single quotes so it doesn’t break the attribute and so it’s valid JavaScript:

    var mailbox = '<form action="mail.php" method="post"><input type="text" onkeyup="showResult(this.value,\''+l+'\')"><input type="submit" name="submit" value="Email"><div id="livesearch"></div></form>';
    

    Note that it is not recommended to attach events in this way because it’s so easy to make this type of mistake. Rather, assign an event handler to the DOM element, not HTML:

    var mailboxHtml;
    var keyUpHandler;
    if (type==1)
    {
        mailboxHtml = '<form action="mail.php" method="post"><input type="text" id="search"><input type="submit" name="submit" value="Email"><div id="livesearch"></div></form>';
        keyUpHandler = function() { showResult(this.value, l); };
    }
    else
    {
        mailboxHtml = '<form action="share.php" method="post"><input type="text" id="search"> Share<div id="livesearch"></div></form>';
        keyUpHandler = function() { showResult(this.value); };
    } 
    
    document.getElementById(target).innerHTML = mailbox;
    document.getElementById('search').onkeyup = keyUpHandler;
    
    return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the below html code with the embedded javascript function disableReturnDate() within
I have a function that requires some vars being appended to a div. One
I have some simple JavaScript functions: function focus(id) { var e = document.getElementById(id); if
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
in .gsp file i have javaScript function <script type=text/javascript> function getCurrentItemNumber(){ return document.getElementById('item_itemNumber').innerHTML.substr(6); }
I have a javascript function below where it removes an appended file name from
I have a JavaScript function buildTable which builds a very long HTML table. function
Suppose I have javascript within ASP.NET UserControl: function setValue(DataItem) { var selectedDate = DataItem.getMember('DomainNameKey').get_object();
I have this HTML: <table class=altRowTable> <script type=text/javascript> $(document).ready(function() { $(table.altRow tr:odd).css(background-color, #DEDFDE); });
I have some php code that is creating an html table. Within it I

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.