Results 1 to 5 of 5
  1. #1
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    Talking Another Javascript Question
    Ok, Here is another brain teaser. I try the following code and I get an undefined error. my question is how do I pass a variable to js file ? I need to pass the veriable from the html file to the js file, Here is what I am doing wrong:



    myhtml.htm

    <script
    mysearch = "current news";
    src="somejava.js">
    </script>


    somejava.js

    document.write("<iframe name=iframe1 src='http://www.google.com/search?q="+mysearch);
    document.write ("' width=530 height=700> marginwidth=1 marginheight=1 border=0 frameborder=0 ");
    document.write("</iframe>");
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  2. #2
    Member
    Join Date
    September 5th, 2005
    Location
    Mansfield, TX
    Posts
    161
    You should be able to just declare it inside the <script> nodes.



    <script language="javascript"
    mysearch = "current news";
    src="somejava.js">

    var myVar = 'something';

    </script>

  3. #3
    Full Member apex-auctions's Avatar
    Join Date
    May 23rd, 2005
    Location
    Lost in Space
    Posts
    277
    Thanks Dholland,

    I found an answer on another board that allows me to use PHP.

    calling file

    <script type="text/javascript" src="somejavascript.php?q=current%20news"></script>


    somejavascript.php
    <?php
    $q='';
    if(isset($_REQUEST['q'])){$q=$_REQUEST['q']};
    ?>
    document.write("<iframe name=iframe1 src='http://www.google.com/search?q=<? echo $q; ?>"
    +"' width=530 height=700 marginwidth=1 marginheight=1 border=0 frameborder=0>"
    +"<\/iframe>");
    Need eBooks ? [URL=http://www.softebooks.com]We gott'em[/URL]:escape:<br>

  4. #4
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    Los Angeles
    Posts
    4,053
    Just to clarify the difference, Java is a (server-side) programming language, and Javascript (JS) is browser-side. They're two completely different things.

  5. #5
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    Very common mistake. I've updated the title.
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  6. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Javascript Question
    By Squerry in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: May 13th, 2009, 10:21 PM
  2. Javascript Code Question
    By Cheesehead in forum Programming / Datafeeds / Tools
    Replies: 5
    Last Post: September 25th, 2007, 06:05 PM
  3. JavaScript Help
    By FunPortal in forum Programming / Datafeeds / Tools
    Replies: 6
    Last Post: August 9th, 2003, 02:14 PM
  4. Javascript question
    By tmd5 in forum Programming / Datafeeds / Tools
    Replies: 6
    Last Post: March 30th, 2002, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •