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>

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/JavaScriptReference/Event-Handlers-Reference/onKeyPressExample.htm
http://www.java2s.com/Code/JavaScript/Event-onMethod/onKeyUpExample.htm

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.


<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.


<form method="get">
    <input type="text" name="place">
    <input type="submit" value="click">
</form>

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?option=com_content&view=article&id=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

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]