Solved

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

Posted on 2009-03-30
12
240 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now