/    Sign up×
Community /Pin to ProfileBookmark

form–textarea,submit

Hi, I have the codes as showed:

[code=php]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>The Blog Warehouse</title>
<meta http-equiv=”content-type”
content=”text/html; charset=iso-8859-1″ />
</head>
<body background=”image/bg-cert-ss.jpg”>
<h3>Search Blog Entries by LSA</h3>

<?php
$dbcnx = @mysql_connect(‘localhost’, ‘root’, ‘password’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the database server at this time.</p>’);
}

// Select the blog database
if (!@mysql_select_db(‘ijob’)) {
exit(‘<p>Unable to locate the blog collection database at this time.</p>’);
}
?>

<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.type.options[form.type.options.selectedIndex].value;
self.location=’search.php?type=’ + val ; //to this file name
}

</script>

<?php

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query(“SELECT DISTINCT name,id FROM blog_type order by name”);
///////////// End of query for first list box////////////
$type=$HTTP_GET_VARS[‘type’]; // This line is added to take care if your global variable is off

if(isset($type) and strlen($type) > 0){
//print_r ($type);

$quer=mysql_query(“SELECT DISTINCT name,id FROM blog_category where typeid=’$type’ order by name”);

}else{$quer=mysql_query(“SELECT DISTINCT name,id FROM blog_category order by name”); }

/////// for second drop down list we will check if category is selected else we will display all the subcategory/////

////////// end of query for second subcategory drop down list box ///////////////////////////
//<form action=”display_title.php” method=”post”>
//echo “<form method=’post’ name=f1 action=’display_title.php’ >”;

echo “<form action=’searchResult.php’ method=’post’ >”;
/// Add your form processing page address to action in above line. Example action=dd-check.php////
////////// Starting of first drop downlist /////////

echo “Blog type: “;
echo “<select name=’type’ onchange=”reload(this.form)”><option value=”>——</option>”;

while($noticia2 = mysql_fetch_array($quer2)) {

if($noticia2[‘id’]==@$type){
$tid = $noticia2[‘id’];
$tname = $noticia2[‘name’];
//print_r ($tid);
//print_r ($tname);
//echo “<option selected value=’$noticia2[id]’>$noticia2[name]</option>”.”<BR>”;}
echo “<option selected value=’$tid’>$tname</option>”.”<BR>”;}
else{//echo “<option value=’$noticia2[id]’>$noticia2[name]</option>/n”;}
$tid = $noticia2[‘id’];
$tname = $noticia2[‘name’];
//print_r ($tid);
//print_r ($tname);
echo “<option value=’$tid’>$tname</option>/n”;}
}
echo “</select>”;

////////////////// This will end the first drop down list ///////////

////////// Starting of second drop downlist /////////

echo ” Category: “;
echo “<select name=’cat’><option value=”>Any Category</option>”;

while($noticia = mysql_fetch_array($quer)) {
$cid = $noticia[‘id’];
$cname = $noticia[‘name’];
//print_r ($cid);
//print_r ($cname);
//echo “<option value=’$noticia[id]’>$noticia[name]</option>/n/n”;
echo “<option value=’$cid’>$cname</option>/n/n”;
}
echo “</select>”;
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////

echo “<p> </P>”;
?>
<form action=<?php echo $_SERVER[‘PHP_SELF’]; ?> method=’post’>
<label>Search Query:<br />
<textarea name= “query” rows=”1″ cols=”100″>
</textarea></label><br />
<p> </P>
<?php
echo “<input type=’submit’ value=’SUBMIT’>”;
echo “<input type=’reset’ name=’RESET’ value=’RESET’>”;
echo “</form>”;

?>

</body>
</html>

[/code]

It is a page for searching. But when I type the search phrase and press “ENTER”, the phrase is gone. I want it to work in the way that when I press “ENTER”, it is actually click on “Submit”. So I changed <textarea > to <input type=”text”. However,I want to keep the text area of the same size as before, such as : rows=”1″ cols=”100″

How to edit the codes further to this purpose? ?

Thanks a lot ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@scragarOct 16.2006 — [code=html]<input type='text' name="query" size="100" value='<?=$_POST['query'];?>'>
[/code]
Copy linkTweet thisAlerts:
@yunfannyauthorOct 16.2006 — Hi, thanks, scragar.

What if I want the text area to be: rows="5" cols="100" ?

Also, is it necessary to put 'valie' in the input?
[code=php]value='<?=$_POST['query'];?>'[/code]
Copy linkTweet thisAlerts:
@scragarOct 16.2006 — you could use CSS to set it's height and width, but it doesn't look like you know how to use it:

[code=html]<style type='text/css'><!--
input#someBox{
height: 8em;
width: 100em;
}
--></style>
<input type='text'
name="query" id='someBox'>[/code]

you should bear in mind though that not all of the area you make available will be capable of writing in(test it if you don't understand), and no, the value atribute is entirely optional, although you should leave it blank if not set to anything for w3 standards.
Copy linkTweet thisAlerts:
@aussie_girlOct 16.2006 — pressing enter or clicking submit button has nothing to do with the textarea element

I put a hidden input value in my forms

<input type="hidden" name="submitted" value="TRUE" />

Then use
[code=php]if (isset($_POST['submitted']))
//all your code here
[/code]

to test if the form has been sent either by pressing enter or clicking submit
Copy linkTweet thisAlerts:
@scragarOct 16.2006 — you mis understand, that code should work, simply stick the style tags in the head, and the input where your text area goes and it should run as expected.
×

Success!

Help @yunfanny spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...