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

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.
designersxAsked:
Who is Participating?
 
Steve BinkConnect With a Mentor Commented:
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
 
Steve BinkCommented:
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
 
Steve BinkCommented:
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
designersxAuthor Commented:
where is the submit button in this? what will be the output? can u tell me please?
0
 
designersxAuthor Commented:
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
 
Steve BinkCommented:
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
 
designersxAuthor Commented:
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
 
Steve BinkCommented:
Do you want the page to refresh when the button is clicked?
0
 
designersxAuthor Commented:
it is not mandatory that i want the page to be refreshed, the only thing i want i that is through button.
0
 
Steve BinkCommented:
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
 
designersxAuthor Commented:
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
 
designersxAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.