PHP - Need To Fill A Selectbox On Selection Of An Item
Help needed
I have a form in which i have 2 selctbox(A & B) In the Select box A i have the star types of hotels On the onchange of selctbox A,I need to perform 2 things 1)I need to fill the selectbox B with the hotelnames from database 2)I need to display all the hotel details saved in the database My code performs the second thing ,but the select box is not filled Code: [Select] <tr><script> function doThis(id) { var selObj = document.getElementById('star'); if(selObj.selectedIndex>0) { var aa=selObj.options[selObj.selectedIndex].value; location.href="ab_search.php?star=" + aa; //location.href="findcity.php?country="+aa; //document.forms["a"].submit(); ///document.a.submit?star=aa; // alert("Selected Value = "+selObj.options[selObj.selectedIndex].value); } } </script> <td width="330"><form action="ab_search.php?star=aa" method="get" id='a' name='a'> <table width="306" class="f_row"> <tr > <td valign="middle" colspan="2"><div class="row"><span class="style17"> Abu Dhabi Hotels</span></div></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> <div style="clear:both"></div> <table height="202" class="s_row"> <tr align="center"> <td width="144" valign="bottom" colspan="2"> <label><span class="style4"> </span></label> <label class="style4">Star Type</label> <br/> <div class="select-box"> <table border='0' height="30" align="center" > <tr> <td align="center" valign="middle"><select id="star" name="star" style='border:none' onChange="doThis(this.value);getCity('findcity.php?country='+this.value)"><!--doThis(this.value);--<option value="0">0</option>--> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option><option value="4">4</option><option value="5">5</option> </select></td> </tr> </table> <p class="style4"> </p> </td> </tr> <tr> <?php $query="select hotel_name from uae_hotels where star_type='$country' and emirates_name='AbuDhabi'";// and star_type=5";// and star_type=$star"; $result=mysql_query($query); ?> <div id="citydiv"> <select name="city" onchange="getResult(<?php echo $country;?>,this.value)"> <option>Select Hotel Name</option> <?php while($row=mysql_fetch_array($result)) { ?><option value="<?php echo $row['hotel_name']; ?>"><?php echo $row['hotel_name']; ?></option> <?php } ?> </select> </div> ?> <td colspan="2"><div class="row"> <label for="destOrHotel_hotel" class="style2"><font color='white'>Hotel Name</font></label> <div style="clear:both"></div> </div> <div id="citydiv"><select name="city"> <option>Select Hotel Name</option> </select></div></td> </tr> <tr> <td height="86" colspan="2" valign="top"><div class="row1"> <input type='submit' name='submitted' id='submitted' value="Submit" /> </div></td> </tr> </table> </form></td> </tr> </table></td> </tr> Similar TutorialsI am creating a simple web application that allows the user to update information in a database. I have a selector that allows the user to select what record they want to update and then a form field to insert the data to be updated. I want the form to to be passed the data from the selected entry "when selected" to auto-complete the default values of the text fields so the user can see the information right in the text fields. This is the form Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Tom's Culture Database</title> <meta name="GENERATOR" content="Quanta Plus"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <style> body { } h3 { color: #585858; } h4 { color : #c00000; } th { background : #000000; border : #ffffff solid 1px; color : #ff0000; text-align : left; } .form_wrapper { background : #000000; padding : 10px; border : solid 2px; } #form_inner { padding : 0 0 0 5px; display : inline-block; } td { border : #000000 solid 1px; } </style> <body> <?php //CONNECT INCLUDE require("connect.php"); //SELECT DATABASE $sql_user_info = mysql_query("SELECT * FROM collections ORDER BY id ASC"); //BEGIN FORM echo "<h3>Select an entry to update or delete!</h3> <form action='mysql_update_action.php' method='POST'><select name='name_select'>"; while ($row = mysql_fetch_assoc($sql_user_info)) { $id = $row['id']; $genus = $row['genus']; $species = $row['species']; $strain_name= $row['strain_name']; echo " <option value = '$id'>$id : $genus $species $strain_name</option> "; } echo "</select> <br><br><br> <DIV class='form_wrapper'> <DIV id='form_inner' align=\"left\"><h4>Genus Name:</h4><INPUT type=\"text\" name=\"to_change_genus_name\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Species Name:</h4><INPUT type=\"text\" name=\"to_change_species_name\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Strain Name:</h4><INPUT type=\"text\"name=\"to_change_strain_name\"></DIV> <DIV id='form_inner' align=\"left\"><h4>P-Value:</h4><INPUT type=\"text\" name=\"to_change_p_value\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Origin:</h4><INPUT type=\"text\" name=\"to_change_origin\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Get From:</h4><INPUT type=\"text\" name=\"to_change_get_from\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Qty:</h4><INPUT type=\"text\" name=\"to_change_qty\"></DIV> <DIV id='form_inner' align=\"left\"><h4>Created:</h4><INPUT type=\"text\" name=\"to_change_date_created\" value=\"M/D/Y\"></DIV><br> <DIV id='form_inner' align=\"left\"><h4>Working Collection:</h4><INPUT type=\"checkbox\" name=\"to_change_work_collection\"></DIV> <DIV id='form_inner' align=\"left\"><h4>DNA Check:</h4><INPUT type=\"checkbox\" name=\"to_change_dna_check\"> </DIV> <br><br> <INPUT type='submit' name='change' value='Update'> <INPUT type='submit' name='name_delete' value='Delete'> </form></DIV>"; //END FORM ?> <?php //SELECT DATABASE $sql_user_info = mysql_query("SELECT * FROM collections ORDER BY id"); while ($row = mysql_fetch_assoc($sql_user_info)) { $id = $row['id']; $genus = $row['genus']; $species = $row['species']; $strain_name = $row['strain_name']; $p_value = $row['p_value']; $origin = $row['origin']; $get_from = $row['get_from']; $qty = $row['qty']; $work_collection = $row['work_collection']; $dna_check = $row['dna_check']; $date_created = $row['date_created']; $last_modified = $row['last_modified']; if ($work_collection == "0"){ $work_collection = "no"; } else { $work_collection = "yes"; } // Define $color=1 echo "<br>"; echo "<table width='400' border='1' align='left' cellpadding='2' cellspacing='0'>"; echo "<tr><th>ID</th><th>Genus</th><th>Species</th><th>Strain Name</th><th>P-Value</th></tr>"; $color= 1; // If $color==1 table row color = #FFC600 if($color==1){ echo "<tr bgcolor='#808080'><td>".$id."</td><td>".$genus."</td><td>".$species."</td></tr>"; // Set $color==2, for switching to other colors $color=2; } // When $color not equal 1, use this table row color else { echo "<tr bgcolor='#ffffff'><td>".$id."</td><td>".$genus."</td><td>".$species."</td></tr>"; // Set $color back to 1 $color='1'; } echo "</table>"; } ?> </body> </html> This is the update actions Code: [Select] <?php //CONNECT INCLUDE require("connect.php"); //GRAB DATA $name_select = $_POST['name_select']; $name_delete = $_POST['name_delete']; $to_change_genus_name = $_POST['to_change_genus_name']; $to_change_species_name = $_POST['to_change_species_name']; $to_change_strain_name = $_POST['to_change_strain_name']; $to_change_p_value = $_POST['to_change_p_value']; $to_change_origin = $_POST['to_change_origin']; $to_change_get_from = $_POST['to_change_get_from']; $to_change_qty = $_POST['to_change_qty']; $to_change_work_collection = $_POST['to_change_work_collection']; $to_change_dna_check = $_POST['to_change_dna_check']; $to_change_date_created = $_POST['to_change_date_created']; $date = strtotime("now"); $current_date = date("m/d/y", $date); if ($name_select&&$to_change_genus_name&&$_POST['change']) { $change = mysql_query("UPDATE collections SET genus='$to_change_genus_name', species='$to_change_species_name' WHERE id='$name_select'"); echo "<br><h2>Data updated</h2><br>"; header( 'Location: http://localhost/sam/Mycelium.eu/mysql_update.php' ) ; } elseif ($_POST['name_delete']) { $delete = mysql_query("DELETE FROM collections WHERE id='$name_select'"); echo "<br><h2>Data deleted</h2><br>"; header( 'Location: http://localhost/sam/Mycelium.eu/mysql_update.php' ) ; } else echo "Please enter some Information"; header( 'Location: http://localhost/sam/Mycelium.eu/mysql_update.php' ) ; ?> I have a script that seems to work well to insert a bookmark into a users database when he/she is logged into the system but I am having a hard time figuring out how I would go about making a work-a-round for having an item selected before being logged in, and inserted after they have logged in or registered. For example, I would like a user to be able to select an Item to add to bookmark whether that user is logged in/registered or not and if they are not, they would be greeted with a login/registration form and after successful login the add bookmark script would be initiated on the item previously selected. What I've got this far: Simple form to add bookmark: <form name="bm_table" action="add_bms.php" method="post"> <input type="text" name="new_url" value="http://" /> <input type="submit" value="Add Bookmark"/> </form> Then I have the add bookmark script: BEGIN php $new_url = $_POST['new_url']; try { check_valid_user(); //cannot get past this part since it ends the script....code below if (!filled_out($_POST)) { throw new Exception('Form not completely filled out.'); } // check URL format if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // check URL is valid if (!(@fopen($new_url, 'r'))) { throw new Exception('Not a valid URL.'); } // try to add bm add_bm($new_url); echo 'Bookmark added.'; // get the bookmarks this user has saved if ($url_array = get_user_urls($_SESSION['valid_user'])) { display_user_urls($url_array); } } catch (Exception $e) { echo $e->getMessage(); } END php Checking valid user - the portion I cannot get past in the above script: function check_valid_user() { // see if somebody is logged in and notify them if not if (isset($_SESSION['valid_user'])) { echo "Logged in as ".$_SESSION['valid_user'].".<br />"; } else { // they are not logged in do_html_heading('Problem:'); echo 'You are not logged in.<br />'; do_html_url('login.php', 'Login'); do_html_footer(); exit; } } How would I go about modifying the script so that a user could fill in the form (later it would be a link...obviously they probably wouldn't be filling in a form that is log-in specific - but same concept I think) Thanks in advance for the help! tec4 Hi there, I think this is a big question but I'd appretiate any help you can provide!! I have a list of items and subitems in a table that looks like this: id parent_id title 1 0 House Chores 2 1 Take Out Trash 3 1 Clean Room 4 0 Grocery List 5 4 Eggs 6 4 Produce 7 6 Lettuce 8 6 Tomato 9 4 Milk I want to display it like this: (+) House Chores: > Take Out Trash > Clean Room (+) Grocery List: > Eggs (+) Produce > Letutce > Tomato > Milk So basically each entry in the table has an unique id and also a parent id if it's nested inside another item. I "sort of" got it figured out in one way, but it doesnt really allow for nested subgroups. I'd like to know how would y'all PHP freaks to this Also taking suggestions for the javascript code to expand/collapse the tree !! Thank you! I have a select box on a form that is populated with the following function: function getStates(){ // OPEN CONNECTION TO MYSQL ON LOCALHOST $dbhost = 'localhost' ; $username = 'root' ; $password = '' ; $conn = mysqli_connect("$dbhost", "$username", "$password"); if (!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_select_db($conn, "mydb"); $retval = mysqli_query($conn, "SELECT * FROM tblstates") or die("Error: " . mysqli_error($conn)); echo "<option value=''>Select one...</option>"; while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { $rec = $row['name']; echo "<option value = " . $row['name']. ">"; echo $row['name']; echo "</option>"; } } On the form I have several text boxes and the following select box: <div class="formfieldgroup"> <label class="label">Birth State/Country: <span class="required">•</span></label> <select class="fatherbirthstate" name="varfatherbirthstate" tabindex="9"><?=getStates()?></select> <span class="form-error2"><?= $varfatherbirthstateErr ?></span> </div> TESTING: I intentionally leave a text box blank so I will get an error and I make sure to make a selection from the select box. PROBLEM: When the form is submitted, the select box doesn't retain the value selected and is reset to "Select one..." QUESTION: How do I go about retaining the selected value when the form errors? I have a select box and I would like to select data click on it and I guess it should reload the page and populate the text boxes i have below with the data from the database. Below is the code so you can have an idea what i'm trying to do. Is this possible and help would be greatly appreciate. Thanks in advance. Code: [Select] <html> <head> <meta name="generator" content="PhpED Version 5.9.5 (Build 5989)"> <title> RSVP Administrator</title> <link rel="shortcut icon" href=""> </head> <body> <fieldset> <legend>Events</legend> <table> <tr> <td> Select an address: </td> <td> <SELECT NAME> <option value=' '> <? echo $option1 ?>;</option> </SELECT> </td> </tr> <tr> <td> Place of Event: </td> <td> <input type="text" name="location" value="<?php if($option1 == " "){ echo " ";} else{ echo $address_1;} ?>"> </td> </tr> <tr> <td> Address 1: </td> <td> <input type="text" name="address_1"> </td> </tr> <tr> <td> Address 2: </td> <td> <input type="text" name="address_2"> </td> </tr> <tr> <td> City: </td> <td> <input type="text" name="city"> </td> </tr> <tr> <td> State: </td> <td> <input type="text" name="state"> </td> </tr> <tr> <td> Zip Code: </td> <td> <input type="text" name="zip_code"> </td> </tr> <tr> <td> Telephone: </td> <td> <input type="text" name="phone"> </td> </tr> </table> </fieldset> </body> </html> Well I am looking to change this url Code: [Select] http://website.com/product.php?Item=2369 to Code: [Select] http://website.com/product.php?Item=Item-Name Heres a snip of the code that handles that. <?php include_once('mysql_connect.php');$id = (int)$_GET['Item'];?>() any help would be appreciated. Any suggestions for using to php to take html form data and fill a pdf form? Anything for cakephp? Thanks hi, i looking for a way to use a auto fill for a inputbox text but all that i found is using a mysql bd. there is any solution using a txt file? stored in server. thanks a lot for your help I have a form that saves the input data as such: Quote bass inshore offshore Array, regional, mid, 70, 40, 2 x yr, all, fellowship knowledge information learnig, one, one, three, four, one, one, two, three, three, four, TPWD round table discussions conservation biology, the guide talking about fishing the venturi, Jack Ellis and TAG fishing in the East Texas creeks., none at present bass inshore offshore Array, regional, mid, 70, 40, 2 x yr, all, fellowship knowledge information learnig, one, one, three, four, one, one, two, three, three, four, TPWD round table discussions conservation biology, the guide talking about fishing the venturi, Jack Ellis and TAG fishing in the East Texas creeks., none at present bass inshore offshore Array, regional, mid, 70, 40, 2 x yr, all, fellowship knowledge information learnig, one, one, three, four, one, one, two, three, three, four, TPWD round table discussions conservation biology, the guide talking about fishing the venturi, Jack Ellis and TAG fishing in the East Texas creeks., none at present This php program reads it back to the screen as it is writen and as you see it above. Code: [Select] <?php $YourFile = "meeting.survey"; $handle = fopen($YourFile, 'r'); while (!feof($handle)) { $Data = fgets($handle); print $Data; print "<hr>"; } fclose($handle); ?> The code below fails. I feel it is because I am using 'explode' incorrectly. Code: [Select] <?php $YourFile = "meeting.survey"; $handle = fopen($YourFile, 'r'); while (!feof($handle)) { $Data = fgets($handle); $answers = explode(',', $Data); print $answers[0]; print $answers[1]; print $answers[2]; print $answers[3]; print $answers[4]; print $answers[5]; print $answers[6]; print $answers[7]; print $answers[8]; print $answers[9]; print $answers[10]; print $answers[11]; print $answers[12]; print $answers[13]; print $answers[14]; print $answers[15]; print $answers[16]; print $answers[17]; print $answers[18]; print $answers[19]; print $answers[20]; print $answers[21]; print "<hr>"; } fclose($handle); ?> My PHP coding skills are minimal at best, any help, direction, comments you have will be greatly appreciated. If you wish to view the survey html go here If you wish to view the php code used to produce the data, Code: [Select] wget http://texasflyfishers.org/quiz/php_tutorial/survey.php If you wish to view a readback of the data go here Everything I've been able to find over the web, tells me this is what I need to do if I want to add some text that tells what each responce means. Code: [Select] <?php $var=$_POST["fname"]; $xmlDoc = new DOMDocument(); $xmlDoc->loadXML($var); $root = $xmlDoc->documentElement; $elms = $root->getElementsByTagName("*"); foreach ($elms as $item) { // gets the name and the value of each $item $tag = $item->nodeName; $value = $item->nodeValue; // outputs the $tag and $value echo $tag. ' = '. $value . ''; I want to use the code above to get all the xml files parent and child names and values and get them into the database. is this going to work? thanks in advance Hi, I've got a pdf catalog which posts an order to a php form. The idea is that that the php page looks like an order form that the client can check before finally hitting 'submit' (i.e. along the lines of go to shopping cart). I'd like the php page to be editable. Meaning clients can not only look at their echoed order, but change it before committing to it. So the catalog order gets put into a php submit form with editable fields. I've read that others have accomplished this with statements like: Code: [Select] value="<?php echo $clientName; ?>" Which should fill the client name input box on the order form with the posted variable. But it doesn't work properly for me, instead, the form field is filled with "<?xml version=" with the expected name on the line benath the input box and " /> on the line beneath that. Placing the input box declaration entirely within php tags doesn't work either (exactly the same output). Code: [Select] <?php echo ("Name: <input class=\"inputbox\" type=\"text\" name=\"clientName\" maxlength=\"40\" value=\"$clientName\"><br>"); ?> Can anyone help? Steve Hi All Not sure if this is possible, but I spend loads of time filling in the same form on a 3rd party website when people send me their details to check. Is there any way I am able to build a php script to read and check their details (can do this bit) and then submit them to a form on another website (can't do this bit)? The form is a hotel booking form and is spread over 4 pages. I have a few questions that deal with cURL. Question #1 Lets say I'm using cURL to fill out a form with multiple pages. Is cURL able to navigate through each page of the form retaining all the previous pages information until I reach the last page, then submit it all without losing any data? Question #2 Lets just say theoretically I was trying to fill out a form with a CAPTCHA (which obviously I can't get past). Is there a way to display the web page with all the other information filled out, and just leave the CAPTCHA blank to be manually inputted? I'm really just looking for yes/no answers, but it would be much appreciated if you are able to point me in the right direction as well! Thanks in advance! atm i have this in a function: Code: [Select] $returnInfo = array(); $returnInfo["totalWords"] = $totalWords; $returnInfo["uniqueWords"] = count($uniqueWords); $returnInfo["positiveWords"] = $positiveWords; $returnInfo["negativeWords"] = $negativeWords; $returnInfo["rating"] = $mappedrating; return $returnInfo; If i recursive print it it says Array instand of my expected values. p.s., i have found examples where the array get's created in 1 line with all there values but i prefer not to do that since it will be a very long line. Hello everyone I'm very new here but i hope you could help me with a tricky problem I no longer know how to approach it because it's difficult to visalize the solution. Anyway, I have a script that goes to the root of a site (with cURL) and picks up categories (links on the site) via regex. All the links are placed into the big array I have. The first layer (dimension) I've managed to create but the problem comes to when I need my script to delve into deeper dimensions. I want, for each link it finds, go to that page and find those subcategories and place it in my array in the correct subarray. If the regex returns 0 matches, go up one step and go to the next node's site, until the whole big array has been exhausted. Is this possible? Please help out guys and gals. I'll provide more info and code if requested. Hi, I am using this code, what i want is to random fill up stepa field with either option a or option b every time i refresh the page, any help is highly appreciated!:
<form action="myc.php" method="get"> <label for="element_1"> </label> <div> <select class="element select medium" name="stepa"> <option value="" selected="selected"></option> <option value="option a" >Advanced Human option a</option> <option value="option b">Advanced Human Option b</option> </select> </div> <br> <input type="submit"> </form>
I have database that is a list of categories that I would like to insert into a switch statement. This is the only way that I know how to do it right off hand and of course it doesn't work. I've looked on the internet and found examples but they are slightly over my head as ways to do it. Depending on $group which comes from the url a title an h1 would be assigned. Code: [Select] $q = "SELECT * FROM categories"; $r = @mysqli_query ($dbc, $q); switch ($group) { if ($r) { //If $r ran OK while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ case '$row['id_cat']': $h1 = '.$row['group']'; break; } } } Thanks S hey guys thanks for the upcoming support how do I set the blue to fill up the remaining width of the while maininfo div? I tried setting the width:auto <div class="maininfo"> <div class="large">2</div> <div class="smallblock"> <div class="smalltop">3</div> <div class="small">4</div> </div> <div class="smallblock"> <div class="smalltop">5</div> <div class="small">6</div> </div> </div> .maininfo { width: 600px; } .large { float: left; height: 95px; background-color: blue; width:auto; } .smallblock { float: right; height: 90px; margin: 0 0 0 5px; width: 20%; } .small { background-color: red; height: 50%; width: 100%; } .smalltop { background-color: red; height: 50%; width: 100%; margin-bottom:5px; }Edit fiddle - JSFiddle I'm trying to get my video to fill the whole of the viewable screen. All I want to be able to see when my site loads is the video and the h1 tag which sits over the bottom of the video - (welcome to website). How can I achieve this please? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style type="text/css"> #logo { position: fixed; top: 10px; left:50px; width:140px; height:50px; background-image: url("paper.gif"); z-index:3; } #opacity { width: 100%; height:460px; color: #fff; opacity: 1.0; filter: alpha(opacity=100); /* For IE8 and earlier */ position: absolute: top:225px; } #content { width: 100%; height:800px; background-color:white; color: #black important!; } .low { border: 0 none; display: inline-block; font-size: 80px; padding: 0 20px; line-height: 100px; margin-bottom: 0; margin-top: 15px; text-transform: uppercase; } h1{font-family: Arial, Helvetica, sans-serif;} #space { width:100%; height:355px; } .red {color:red;} html, body { margin:0; padding:0; } #nav { height:70px; width:100%; display: none; position: fixed; background-color:#fff; z-index: 2; } video { width: 100% !important; height: auto !important; visibility:hidden; } #videoclip { position: fixed; z-index: -1; } </style> <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script> <script type='text/javascript'>//<![CDATA[ $(window).load(function(){ $(window).bind("scroll", function() { if ($(this).scrollTop() > 50) { $("#nav").fadeIn(); } else { $("#nav").stop().fadeOut(); } }); });//]]> </script> <script type='text/javascript'> jQuery(document).ready(function(){ /* stop the black video loading box */ delayShow(); }); function delayShow() { var secs = 400; setTimeout('jQuery("video").css("visibility","visible");', secs); } </script> </head> <body> <div id="logo"><img src="http://www.blackdog.london/sites/default/files/bdlogo.png" width="100%" height="100%" alt="Home"></a></div> <div id="nav"></div> <div id="videoclip"> <video autoplay loop> <source src="walking.mp4" type="video/mp4"> <source src="walking.ogg" type="video/ogg"> <source src="walking.mov" type="video/mov"> <img src="frame1.png"/> Your browser does not support the video tag. </video> </div> <div id="opacity"> <div id="space"></div> <h1 class="low">welcome to website</h1> </div> <div id="content"><h1 class="low">content <span class="red">here<span></h1></div> </body> </html> |