SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to use javascript variable in html tag

    Hi

    all

    How to use javascript variable in html tag

    code
    <html>
    <head>
    <script type="text/javascript">

    var t=form1.city.value;
    </script>
    </head>

    <form name="form1" id="form1">
    <input type="text" name="city" id="city">

    <a href="c:/test.php?place=t>click</a>
    </form>
    </html>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You will need to use a key event either been onkeyup or onkeypress in order to change the URL of the anchor element, you can find all the information you need on Google. Here are some examples i found

    http://www.java2s.com/Code/JavaScrip...essExample.htm
    http://www.java2s.com/Code/JavaScrip...yUpExample.htm

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    How to use javascript variable in html tag
    In your situation it seems that you do not use JavaScript at all.
    Instead, use the get method for submitting your form, and give the field a name of "place". That will cause the form to submit with the appropriate information in the location bar.

    Code html4strict:
    <form method="get">
        <input type="text" name="place">
    </form>

    Without a submit button the user can just press enter after typing in the field, and the form submits automatically.

    Here is an alternative that uses a submit button.

    Code html4strict:
    <form method="get">
        <input type="text" name="place">
        <input type="submit" value="click">
    </form>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear

    Paul

    thanks for your reply


    I am developing a small website in joomla. when user fills the form i want to collect those values and execute a query based on those values in test.php file. In the same file I am creating a table which I want to display in joomla.

    Here is the code

    <html>
    <head>
    <title>Online Booking Search</title>
    <link rel="stylesheet" href="testproject/jscripts/booking.css">
    <link rel="stylesheet" href="testproject/jscripts/reports.css">
    <script type="text/javascript" src="testproject/jscripts/reports.js"> </script>
    </head>
    <?php
    include("config1.php");
    $car=$_POST['vehicle'];
    $package=$_POST['package_details'];

    $query=mysql_query("SELECT a.package_details,b.fare FROM pck_master a, pck_details b WHERE a.package_id='$package' ") or die('error'.mysql_error());
    while($data2 =mysql_fetch_array($query))
    {
    $pac=$data2['package_details'];
    $fare=$data2['fare'];
    }
    print"<br><br><br><br>";
    print"<table id='myTable' width='730' >";

    print "<thead align='left'>";
    print"<tr><td><FONT COLOR='#800517'>Cab Name</td> <td><FONT COLOR='#800517'>Vehicle</td><td><FONT COLOR='#800517'>Package</td><td><FONT COLOR='#800517'>Date</td><td><FONT COLOR='#800517' scope='col'>Amount</td><td><FONT COLOR='#800517'> </td>";
    print"</thead>";
    print"<tbody align='left'>";
    $sql = "SELECT image FROM tbl_images";
    $result = mysql_query("$sql");
    //print("Content-type: image/jpeg");
    $k= mysql_result($result, 0);
    print "<td width='10%'>";
    print '<img src="data:image/jpeg;base64,'.base64_encode($k).'" width="60" height="40" >';
    print "</td><td>";
    print $car;
    print "</td><td>";
    print $pac;
    print "</td><td>";
    print $date;
    print "</td><td>";
    print $fare;
    print "</td></font></tr>";

    print "</tbody>";
    print "</table>";

    //print '<meta http-equiv="refresh" content="1;URL=/testl/index.php?option=com_content&view=article&id=74&Itemid=503\">';
    //header( 'Location: http://192.168.1.5/test/index.php?op...=74&Itemid=503') ;
    ?>
    <!--meta http-equiv="refresh" content="1;URL=/test/index.php?option=com_content&view=article&id=74&Itemid=503"-->
    <script type="text/javascript">
    addTableRolloverEffect('myTable','tableRollOverEffect1','tableRowClickEffect1');
    </script>

    </table>
    </form>
    </body>
    </html>

    when I am using php header function it is giving error output already sent. Because I used echo statements.
    I used meta tag but it is refreshing the page for every one second.

    so I thought to make I hyperlink on the button in the front form

    <a href="/test/index.php?option=com_content&view=article&id=74&Itemid=503&t1=test&t2=t3><input type="button" name="button" value="click"></a>

    please help me out to achieve this

    Thanks & Regards
    MD.Samiuddin

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    I am developing a small website in joomla
    Have you considered using the tools that Joomla provides, which allow you to perform your task in easier ways?

    Here is the Joomla 1.6/1.7 forum which can help you to use Joomla most effectively, in order to achieve what you need to do.[/quote]
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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