Solved

place the fields at a particular position (left, right, top, bottom) as selected by the admin.

Posted on 2009-03-30
12
265 Views
Last Modified: 2012-05-06
i have the following fields and each field is in separate div and there is a drop down menu in front of each field having options are left, right, top, middle, bottom. these fields are in the admin part.

name (div1)    -  there is a drop down menu (options are left, right, top, bottom,middle)
company address (div2)    -  there is a drop down menu (options are left, right, top, bottom,middle)
full name  (div3)    -  there is a drop down menu (options are left, right, top, bottom,middle)
address line 1  (div4)    -  there is a drop down menu (options are left, right, top, bottom,middle)

Below there is a submit button, on clicking the button, according to the options selected by the user, that field should be placed at that position.
0
Comment
Question by:designersx
  • 6
  • 6
12 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 24024948
The user selections will be passed to your page through $_POST.  It should be a simple matter of examining those selections, and creating the div with the appropriate class.  For example, imagine I have this CSS entry:

<style>
  div.option_topleft { position:absolute;top:0;left:0 }
  div.option_bottomright { position:absolute;top:300;left:250 }
</style>

Now take a look at this code:
<?
/*
based on:
<input type="text" name="ctl_name" value="" />
<select name="ctl_name_pos">
  <option value="0">Top Left</option>
  <option value="1">Bottom Right</option>
</select>
*/
 
$controls = array('ctl_name');  // put all your control names
foreach ($controls as $key=>$val) {
  switch($controls["{$key}_pos"]) {
    case 0:$class="topleft";break;
    case 1:$class="bottomright";break;
    default:$class="";break;
  }
  echo "<div class=\"$class\">$val</div>";
}
?>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 24024957
DOH...forgot the part about $_POST...  :)


<?
/*
based on:
<input type="text" name="ctl_name" value="" />
<select name="ctl_name_pos">
  <option value="0">Top Left</option>
  <option value="1">Bottom Right</option>
</select>
*/
 
$controls = array('ctl_name');  // put all your control names
foreach ($controls as $key) {
  switch($_POST["{$key}_pos"]) {
    case 0:$class="topleft";break;
    case 1:$class="bottomright";break;
    default:$class="";break;
  }
  echo "<div class=\"$class\">",$_POST[$key],"</div>";
}
?>

Open in new window

0
 

Author Comment

by:designersx
ID: 24025672
where is the submit button in this? what will be the output? can u tell me please?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:designersx
ID: 24025789
Sir, my simple question is this

how to move the text on a window as selected by the user from a drop down menu on clicking the button ?
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 24026226
The submit was not important to my example, so I did not include it.  When the user clicked the submit button, the page would be refreshed with the correct class for each div.  I assumed you wanted this in PHP because you posted this question in the PHP zone.

If you want this to be done through javascript, take a look at the example below.

<script type="text/javascript">
  function changepos() {
    var x;
    x = document.getElementById('selpos').selectedIndex;
    y = document.getElementById('test');
    switch(x) {
    	case 0: y.style.top='50px';y.style.left='200px';break;
    	case 1: y.style.top='350px';y.style.left='200px';break;
    	case 2: y.style.top='200px';y.style.left='0px';break;
    	case 3: y.style.top='200px';y.style.left='400px';break;
    }
  }
</script>
<style>
  #test { width:200px;height:50px;position:absolute;top:50px;left:200px; }
</style>
<form>
  <div class="t1" id="test">Stuff</div>
  <select id="selpos" onchange="changepos();">
  	<option value="0">Top</option>
  	<option value="1">Bottom</option>
  	<option value="2">Left</option>
  	<option value="3">Right</option>
  </select>
</form>

Open in new window

0
 

Author Comment

by:designersx
ID: 24026295
this was exactly i wanted, thanks buddy for this.

Actually buddy, this is exactly ok but can u do it if i have a submit button

with ur previous code, nothing happens with this code when i tested.

<?
/*
based on:
<input type="text" name="ctl_name" value="" />
<select name="ctl_name_pos">
  <option value="0">Top Left</option>
  <option value="1">Bottom Right</option>
</select>
*/
 
$controls = array('ctl_name');  // put all your control names
foreach ($controls as $key) {
  switch($_POST["{$key}_pos"]) {
    case 0:$class="topleft";break;
    case 1:$class="bottomright";break;
    default:$class="";break;
  }
  echo "<div class=\"$class\">",$_POST[$key],"</div>";
}
?>
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 24026369
Do you want the page to refresh when the button is clicked?
0
 

Author Comment

by:designersx
ID: 24026776
it is not mandatory that i want the page to be refreshed, the only thing i want i that is through button.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 24028701
Using the PHP style, you can just put a regular form button as the submit.  Make sure the form method="POST" and that action points back to the same filename.

<input type="submit" name="dosubmit" value="Place Items" />
0
 

Author Comment

by:designersx
ID: 24036250
with php , text goes in the bottom for 1 second and then comes to its place when i select bottom and clik the submit button. This happens for all the the positions.


yogesh
<script type="text/javascript">
  function changepos() {
    var x;
    x = document.getElementById('selpos').selectedIndex;
    y = document.getElementById('test');
    switch(x) {
        case 0: y.style.top='50px';y.style.left='200px';break;
        case 1: y.style.top='350px';y.style.left='200px';break;
        case 2: y.style.top='200px';y.style.left='0px';break;
        case 3: y.style.top='200px';y.style.left='400px';break;
    }
  }
</script>
<style>
  #test { width:200px;height:50px;position:absolute;top:50px;left:200px; }
</style>
<form action="ox_print_left_right_2nd.php" method="post" name="form" onSubmit="javascript:changepos();">
  <div class="t1" id="test">Stuff</div>
  <select id="selpos">
        <option value="0">Top</option>
        <option value="1">Bottom</option>
        <option value="2">Left</option>
        <option value="3">Right</option>
  </select>
  <input type="submit" name="dosubmit" value="Place Items" />
</form>

Open in new window

0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 200 total points
ID: 24036271
You mixed up the styles.  You have all the code for the javascript method, but you are letting the form submit to PHP.  Try this change, and don't use the submit button:
<script type="text/javascript">
  function changepos() {
    var x;
    x = document.getElementById('selpos').selectedIndex;
    y = document.getElementById('test');
    switch(x) {
        case 0: y.style.top='50px';y.style.left='200px';break;
        case 1: y.style.top='350px';y.style.left='200px';break;
        case 2: y.style.top='200px';y.style.left='0px';break;
        case 3: y.style.top='200px';y.style.left='400px';break;
    }
  }
</script>
<style>
  #test { width:200px;height:50px;position:absolute;top:50px;left:200px; }
</style>
<form action="ox_print_left_right_2nd.php" method="post" name="form">
  <div class="t1" id="test">Stuff</div>
  <select id="selpos" onchange="javascript:changepos();">
        <option value="0">Top</option>
        <option value="1">Bottom</option>
        <option value="2">Left</option>
        <option value="3">Right</option>
  </select>
  <input type="submit" name="dosubmit" value="Place Items" />
</form>

Open in new window

0
 

Author Comment

by:designersx
ID: 24036306
your above code is working same as ur previous code. but it clicked me and i have done it.

see the code. now on selecting the options the div will not change but on clicking the button it will change.
but otherwise thanks for ur help.

yogesh

<script type="text/javascript">
  function changepos() {
    var x;
    x = document.getElementById('selpos').selectedIndex;
    y = document.getElementById('test');
    switch(x) {
        case 0: y.style.top='50px';y.style.left='200px';break;
        case 1: y.style.top='350px';y.style.left='200px';break;
        case 2: y.style.top='200px';y.style.left='0px';break;
        case 3: y.style.top='200px';y.style.left='400px';break;
    }
  }
</script>
<style>
  #test { width:200px;height:50px;position:absolute;top:50px;left:200px; }
</style>
<form action="ox_print_left_right_2nd.php" method="post" name="form">
  <div class="t1" id="test">Stuff</div>
  <select id="selpos">
        <option value="0">Top</option>
        <option value="1">Bottom</option>
        <option value="2">Left</option>
        <option value="3">Right</option>
  </select>
  <input type="button" name="dosubmit" value="Place Items" onclick="changepos();" />
</form>

Open in new window

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question