Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Variable Help - Change CSS with PHP?
Old 07-15-2009, 11:41 PM Variable Help - Change CSS with PHP?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 824
Name: Scott
Location: Ontario
Trades: 0
Hello.

I am trying to make a text box with the name as '$value'. I am trying to make a div change to whatever size you specify on the page with PHP. Here is my code:

Code:
<?php echo "<input name='$value' type='text' />

<div id='samplediv'>HELLO!</div>

<script type='text/javascript'>
document.getElementById('samplediv').style.width = '$value';
</script>

"; ?>
I know I'm doing a stupid mistake, I just do'nt know what. I'm a total PHP n00b, so please go easy on me
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-16-2009, 12:19 AM Re: Variable Help - Change CSS with PHP?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try something like this:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <script type="text/javascript">
  var allowed_sizing = [100,1024]; //Min to max width
  function resizeDiv() {
    //Grab value from field and convert to INT
    var desired_size = parseInt(document.getElementById("div_size").value);
    
    //If the value does not come out as a numerical result, convert to smallest allowed sizing
    if (isNaN(desired_size)) {
      desired_size = allowed_sizing[0];
    }
    
    //Constrain values to between the min and max allowed.
    desired_size = Math.max(Math.min(desired_size, allowed_sizing[1]),allowed_sizing[0]);
    
    //Update stylesheet value
    document.getElementById("samplediv").style.width = desired_size + "px";
    
    //Now, in case we changed the user's value, let's update the input box.
    document.getElementById("div_size").value = desired_size;
  }
  </script>
  <style type="text/css">
  #samplediv {
    border:1px #000 solid;
  }
  </style>
</head>
<body>
<input name="div_size" id="div_size" type="text" />
<input type="button" value="Size My Div" onClick="resizeDiv();"/>
<!--
Note that this div, as a block element, will initially go across the entire page.
-->
<div id="samplediv">HELLO!</div>
</body>
</html>
No PHP is needed.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-16-2009, 10:12 AM Re: Variable Help - Change CSS with PHP?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 824
Name: Scott
Location: Ontario
Trades: 0
Wow, that works like a dream! I'll list you in the Developer Credits!

Thanks!!
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Variable Help - Change CSS with PHP?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38364 seconds with 12 queries