Solved

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

Posted on 2009-03-30
12
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 51

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 51

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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 

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 51

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 51

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 51

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 51

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

635 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