set html dropdown to selected value after refresh - html

how do i set a dropdown menu to a get variable after refresh. there is an html menu and after a refresh i would like the dropdown to be set to the select variable. for example if i select 3 from the menu then click submit the dropdown should display 3. i used to do this with textboxes where i would set the value to the get variable im just trying to do this same technique with html dropdown menus.
</select>
<?php
$c=$_GET['c'];
$p=$_GET['p'];
$id=$_GET['id'];
if ($c!=NULL){
$sq=mysql_query("SELECT * FROM ps WHERE b='$id' AND c='$c'");
while ($row=mysql_fetch_assoc($sq)) {
$start=$row['start'];
$start=trim($start);
$m=$row['m'];
}
echo "<select type='text' name='pro' id='amount' value= '$p'>";
echo "<option value=''>P</option>";
while ($start<=$m){
echo "<option value='$start'>$start</option>";
$start++;
}
}
?>
</select>

Is this in a form? If so you echo options like this:
echo "<option value='$start'";
if (isset($_POST['pro']) && ($_POST['pro']==$start)) echo " selected='selected'";
echo ">$start</option>\n";
But first you need to submit the form though.
The idea is that you compare the value of a set variable for this select element to current value of $start within the loop, and print 'selected' if they match.

Is this what you meant??
http://www.plus2net.com/php_tutorial/pb-drop.php

Related

How to center allign input forms

In my page I am having one drop-down, 3 text boxes and one submit button .As of now it is left alligned . I need to make it center alligned. I am using bootstrap css in my code. I am new to this field . Can someone tell how to do that . I have tried this:
<?php
echo "<form action=page2.php method=GET>";
echo '<td><select class="form-control" name="select-val">
<option value="a1">A1</option>
<option value="a2">A2</option>
<option value="a3">A3</option>
<option value="a4">A4</option>
<option value="a5">A5</option>
<option value="a6">A6</option>
</select></td>';
echo "<br>";
echo "<td>" ." <input align='center' type = text class = form-control name = sel_val
placeholder = 'Enter The Name'>". "</td>";
echo"<br>";
echo"<br>";echo "<td>" ." <input align='center' type = text class = form-control name = start_date
placeholder = 'Start Date(YYYY-MM-DD)'>". "</td>";
echo"<br>";
echo "<td>" ." <input align='center' type = text class = form-control name = end_date
placeholder = 'End Date(YYYY-MM-DD)'>". "</td>";
echo"<br>";
echo "<td>" ."<input align='center' class=btn type=submit value=select". "></td>";
echo "</form>";
?>
Thanks in advance.
First of all, don't use tables for layouts; it's bad practise if you aren't showing any tabular data.
There are a couple of ways of going about this
Method 1) I prefer this one as it makes the most sense but if you want the elements to be in different rows you can't use this method
On all the inputs and elements you want centered add display: inline-block. Then on the container element that encapsulates all of this add text-align: center.
This will center all the elements horizontally and should appear how you want it.
Method 2) You can also add a position: relative to all the elements and then do left: 50%; margin-left: -[half of your element width]. This also works and allows the elements to be on different rows while remaining horizontally centered.

How to get HTML of a sidebar content in wordpress?

I can get a list of sidebars by going through wp_registered_sidebars
<?php foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { ?>
<input value="<?php echo ucwords( $sidebar['id'] ); ?>">
<?php echo ucwords( $sidebar['name'] ); ?>
<?php } ?>
And I can output the sidebar with
<?php echo dynamic_sidebar( ucwords( $sidebar['id'] )); ?>
But I need to output the HTML content out.
I am trying to insert the sidebar in a menu (megamenu), and I am following this post on how to get the metabox appear in my Menus page. I've done it all, I can get the name, id of the sidebar, everything. It's just when I try to add HTML content in my description field of the menu, I don't know how. If I put the dynamic_sidebar I'll get the actuall sidebar in my menus page, and that's not what I want.
So any help is appreciated.
Is it possible to do it with ob_start() function?
EDIT
I tried with:
<?php
ob_start();
dynamic_sidebar($sidebar['id']);
$sidebar_html = ob_get_contents();
ob_end_clean();
?>
But when I echo that variable inside the hidden input field
<input type="hidden" class="menu-item-description" name="menu-item[-1][menu-item-description]" value="<?php echo $sidebar_html; ?>">
I still get the html out. I just need it as a text html that won't be 'executed'.
Ok, htmlentities() did it
<input type="hidden" class="menu-item-description" name="menu-item[-1][menu-item-description]" value="<?php echo htmlentities($sidebar_html); ?>">

Using tickboxes to select which class to use

I am just wondering if there is anyway to make it so that the css class of a DIV can be changed by the selection of a tick box.
For example I have this checkbox HTML
<input type="checkbox" name="size" id="portrait1" value="portrait"> Portrait
<input type="checkbox" name="size" id="landscape1" value="landscape"> Landscape
and then this div (used on concrete5 so might make no sense to some)
<div class="" style="display: none;">
<?php echo $form->label('content', t('Title'))
?>
<?php echo $form->text('content')
?>
<br>
<br>
<?php echo $al -> file('ccm-b-file', 'fID', t('Choose File'), $bf); ?>
<?php $bf = File::getByID($fID); ?>
<br>
<?php echo $form->label('UserURL', t('URL:'))
?>
<?php echo $form->text('UserURL')
?>
</div>
but i want it so that when I click portrait, for example, the class of that div changes to say portrait, any way of doing this?
You can do this with a bit of JavaScript.
You'll need to bind an event handler to your checkbox (that is, tell the browser to run a chunk of code when a certain event happens: the event in question being changing the state of the checkbox.)
(Note: I am using jQuery in my example for brevity.)
$("checkbox#portrait1").bind('change', function() {
$("div").toggleClass('portrait', $(this).is(":checked"))
});
The above example binds the given function to the "change" event of the given selector (input#portrait1, i.e. input element with the ID of portrait1).
When that event happens, it then "toggles" the class portrait on the div element based on whether the second argument is true or not, meaning if "this" (the checkbox input) is checked, then the class portrait will be added to that div (if not, remove the class of portrait).
Try this....
$('input[name=size]').click(function(){
if($(this).is(':checked'))
$('div').addClass('test')
else
$('div').removeClass('test')
})
Always have a default id for div like
<div class="" style="display: none;" id="a1">
<?php echo $form->label('content', t('Title'))
?>
<?php echo $form->text('content')
?>
<br>
<br>
<?php echo $al -> file('ccm-b-file', 'fID', t('Choose File'), $bf); ?>
<?php $bf = File::getByID($fID); ?>
<br>
<?php echo $form->label('UserURL', t('URL:'))
?>
<?php echo $form->text('UserURL')
?>
</div>
and in javascript
if(document.getElementById("portrait1").checked == true)
{
document.getElementById("a1").class="portrait";
}
else if(document.getElementById("landscape").checked == true)
{
document.getElementById("a1").class="landscape";
}

Looking to select a drop down menu item based on the url the user enters the page from

I have 10 different camp sites on a client site, I want to select a camp location based on where they what camp site they click on "registration form" from.
Currently it is a 10 item drop down, and I am looking to either do this through a url parameter (foo.com/test.html?camp=value) or something like that, but I cannot figure this out.
Hope fully you guys and gals can come through for me again!
Something like this if you are using php (using query string ?camp=value):
<?php
$camp = isset($_GET['camp']) ? $_GET['camp'] : NULL;
$sel = ' selected="selected"';
?>
<select>
<option value="value1"<?php if ($camp === 'value1') echo $sel; ?>>
Value 1
</option>
<option value="value2"<?php if ($camp === 'value2') echo $sel; ?>>
Value 2
</option>
</select>
Not sure if you're using php, but maybe this will help anyways.

Adding a radio button against each record

The following code uses the DB extention provided by PEAR.
I want a radio button against each record so that the user can select only one record from the list and submit. There can be hundreds of records from table.
// Proceed with getting some data...
$res =& $db->query('SELECT * FROM someTable limit 10');
while ($res->fetchInto($row)) {
echo "<tr><td>";
echo $row[0] . "\n</td><td>";
echo $row[1] . "\n </td><td>";
echo $row[2] . "\n</td><td>";
echo $row[5] . "\n</td><td>";
echo $row[6] . "\n</td>";
echo "</tr>";
}
ok so put an <input type="radio" name="same-name-for-each" value="$this_record" /> between each table cell.
each radio button gets the same name
the value of each radio button needs to be different - the id or value of whichever option the selected radio represents.