Click to See Complete Forum and Search --> : How to do automatic Release of item in Listbox?
toplisek
12-17-2008, 03:24 AM
Sample code for listbox is the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<select>
<option value="">Define Listbox --></option>
<optgroup label="Your best car">
<option value ="volvo">Volvo</option>
</optgroup>
<optgroup label="Your quote">
<option value ="mercedes">Mercedes</option>
</optgroup>
</select>
</body>
</html>
How to make automatic release of particular item if user decides for item Mercedes or item like Volvo?
Explain "automatic release".
toplisek
12-17-2008, 07:08 AM
Explain "automatic release".
Simply:
Release means execution of item.
So, When I decide to see Volvo, it will be redirected to Volvo page without Go button. Old sample is to decide and choose item like Volvo and Click Go button.
I would like to work without Go button.
http://javascript.internet.com/generators/drop-down-menu.html
toplisek
12-17-2008, 09:40 AM
thank you. It works, but has 3 errors and do not know how to avoid when validating:
1. required attribute "action" not specified.
<form name="jump">
2. there is no attribute "onChange".
<select name="menu" onChange="location=document.jump.menu.options[document.jump.
3. there is no attribute "value".
…mp.menu.selectedIndex].value;" value="GO">
toplisek
12-17-2008, 09:51 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<form name="jump">
<select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">
<optgroup label="my car option">
<option value ="www.mydomain.com">Volvo</option>
</optgroup>
<optgroup label="my quote">
<option value ="www.mydomain.com">Mercedes</option>
</optgroup>
</select>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<form name="jump">
<select name="menu" onChange="location=this.value;" value="GO">
<optgroup label="my car option">
<option value ="http://www.mydomain.com/">Volvo</option>
</optgroup>
<optgroup label="my quote">
<option value ="http://www.mydomain.com/">Mercedes</option>
</optgroup>
</select>
</form>
</body>
</html>
toplisek
12-18-2008, 03:54 AM
you code has still errors when validating:
# Line 21, Column 17: required attribute "action" not specified.
<form name="jump">
✉
The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.
Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.
# Error Line 22, Column 29: there is no attribute "onChange".
<select name="menu" onChange="location=this.value;" value="GO">
✉
You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).
This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.
How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the <embed> element to incorporate flash media in a Web page, see the FAQ item on valid flash.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form name="jump" action="location.php">
<div>
<select name="menu" onchange="location=this.value;">
<optgroup label="my car option">
<option value ="http://www.mydomain.com/">Volvo</option>
</optgroup>
<optgroup label="my quote">
<option value ="http://www.mydomain.com/">Mercedes</option>
</optgroup>
</select>
</div>
</form>
</body>
</html>
toplisek
12-18-2008, 06:51 AM
thank you. Perfect.
what actually influence value:action="location.php"
Is this main file and needed?
This would be a script that is called to change the page when JavaScript is unavailable.
toplisek
12-18-2008, 07:25 AM
Should I add new page as I would like just to show the same page but without Javacript if Javascript will be unavailable? Than I leave just index.php. Correct?
toplisek
12-29-2008, 10:37 AM
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form name="jump" action="location.php">
<div>
<select name="menu" onchange="location=this.value;">
<optgroup label="my car option">
<option value ="http://www.mydomain.com/">Volvo</option>
/code]
How to avoid using value as URL as I need value volvo not URL? Is this possible to be achieved but keep also redirection to URL?
onchange="alert(this.options[this.options.selectedIndex].text); location=this.value;"
toplisek
12-29-2008, 02:54 PM
I think there is missing also change in value in items (listbox).
Where to define value and where URL?
Currently there is the following:
Example:
<select name="menu" onchange="alert(this.options[this.options.selectedIndex].text); location=this.value;">
<optgroup label="my car option">
<option value ="http://www.mydomain.com/">Volvo</option>
I would like to store value Volvo not URL but redirection to URL as now.
Store the text value where?
toplisek
12-30-2008, 03:55 AM
Store the text value where?
I would like to store value of particular item like volvo, mercedes...to track search item.
The number of times a page is opened will give you that. Look at your log files.
toplisek
12-30-2008, 08:14 AM
I know this. So, is possible to have atribute value=volvo and href?
value is not a valid attribute of an anchor.
toplisek
12-30-2008, 08:40 AM
value is not a valid attribute of an anchor.
I have code with added PHP as following:
<?
if(isset($_POST['search1'])){
$email='user1@email.com';
$subject='Search record';
$message=" The selected search value was: ".$_POST['search1'];
mail($email,$subject,$message);
}
?>
<form name="jump" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>" method="post">
<div>
<select name="search1" id="search1" onchange="location=this.value;">
<option value="">Please choose</option>
<optgroup label="My quote">
<option value ="page1.html">Volvo</option>
<option value ="page2.html">Mercedes</option>
</optgroup>
</select>
</div>
</form>
Maybe I was not so clear with all elements.
As you can see there is URL like page name and value of Listbox like Volvo or Mercedes. I would like to be sent volvo value not URL of page.
<?php
if(isset($_POST['search1'])){
$email='user1@email.com';
$subject='Search record';
list($url, $query) = split("\?", $_POST['search1']);
$message=" The selected search value was: ".$query;
mail($email,$subject,$message);
header("Location: $url");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<form name="jump" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<div>
<select name="search1" id="search1" onchange="this.form.submit();">
<option value="">Please choose</option>
<optgroup label="My quote">
<option value ="page1.html?Volvo">Volvo</option>
<option value ="page2.html?Mercedes">Mercedes</option>
</optgroup>
</select>
</div>
</form>
</body>
</html>
toplisek
12-30-2008, 09:29 AM
this modified code will send URL. If I understand, I have to change value of URL with PHP and send report of search. Right?
toplisek
12-30-2008, 10:16 AM
Value $query will not be sent per mail.I think there some issue with
list($url, $query) = split("\?", $_POST['search1']);
$message=" The selected search value was: ".$query;
toplisek
12-30-2008, 10:32 AM
I have issue with this script.
It does not send variable query. It goes to index.php (SELF page). Do not know why but it does not redirects and also not sent variable query. I use rewrite rules but URL in listbox items are correct.
Split function will not be correct in my case and also code does not redirect. I have simple SEO friendly URL's...
If I use location=this.value; will work but not showing variable query in mail function.
It does not send variable query.The script will send and redirect if used as given.I have simple SEO friendly URL's...
Doubtful or there would be a correlation between the url and the text value.
toplisek
12-31-2008, 04:13 AM
The script will send and redirect if used as given.Doubtful or there would be a correlation between the url and the text value.
What is difference between this.form.submit(); and location=this.value;
as location=this.value; will redirect to correct URL.
this.form.submit() will allow the php to send the mail and redirect.
location=this.value will only redirect.
toplisek
12-31-2008, 09:59 AM
Strange that mail works without query variable and it does not redirect correctly with onchange="this.form.submit();
It redirects to the same page.