?
Solved

Problem with button text inserting a second line

Posted on 2012-08-28
20
Medium Priority
?
405 Views
Last Modified: 2012-09-01
The following code generates a new line in the button:

   <!-- Print Format Button -->
            <td align = "center" width="275">
        <input name="Print_Formats" type="button" id="Print_Formats" onClick="MM_goToURL('parent', 'Print_Formats.php');return document.MM_returnValue" value="Print Format
        <?php
            echo '&#';
            $work = (9311 + $_SESSION['P_Format']);
            echo $work;
            echo '"';
            ?>
       
        ">

          </td>  
      <!-- End Print Format Button -->

The $work does generate the correct symbol (in this case a 1 in a circle).  I've tried increasing the size of the column and the button size.  It still does a carriage return and the number ends up on the second line.

What am I missing?
0
Comment
Question by:breeze351
  • 9
  • 5
  • 4
  • +1
20 Comments
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38344685
Try this
<input name="Print_Formats" type="button" id="Print_Formats" onClick="MM_goToURL('parent', 'Print_Formats.php');return document.MM_returnValue" value="Print Format <?php
            echo '&#';
            $work = (9311 + $_SESSION['P_Format']);
            echo $work;?>">

Open in new window

Put the <?php on the same line as the "Print Format"
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38345446
You can create the variable in PHP and use short-output notation to add it to the browser output string.  Easy!
http://www.laprbass.com/RAY_temp_breeze351.php

<?php // RAY_temp_breeze351.php
error_reporting(E_ALL);

// LOAD THIS VARIABLE TO PREVENT NOTICE-LEVEL MESSAGES
$_SESSION['P_Format'] = '2';

// SET THE VALUE
$val = 9311 + $_SESSION['P_Format'];

// CREATE A STRING FROM COMPONENT PARTS
$str
= 'Print Format'
. ' '
. '&#'
. "$val"
;

// DROP INTO HTML AND SEE WHAT IS RENDERED IN THE VALUE= ATTRIBUTE
?><!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8" />


   <!-- Print Format Button -->
            <td align = "center" width="275">
        <input
        name="Print_Formats"
        type="button"
        id="Print_Formats"
        onClick="MM_goToURL('parent', 'Print_Formats.php');return document.MM_returnValue"
        value="<?=$str;?>" />

          </td>
      <!-- End Print Format Button -->

Open in new window

0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38345514
Damn, Ray, you beat me to it. I'd do it how Ray shows.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38345526
Hi, Eddie.  Great minds think alike!

;-)

~Ray
0
 

Author Comment

by:breeze351
ID: 38346973
Ok, the number is on the same line now; however the button is still looks like it has a new carriage return.

I changed the code to read:

    <!-- Print Format Button -->
    <?php
      // Set The Value Of The Button
    $work = (9311 + $_SESSION['P_Format']);
      
      // Create The Button Value
      $Button_Value = 'Print Format - '
      . ' '
      . '&#'
      . "$work";
      ?>
            <td align = "center" width="156">
        <input name="" type="button" id="Print_Formats" onClick="MM_goToURL('parent', 'Print_Formats.php');return document.MM_returnValue" value="
        <?php
            echo $Button_Value;
            ?>
       
        ">

          </td>  
      <!-- End Print Format Button -->  

Two more questions on the same subject:
1:  I would like to change the color on the number in the circle.
2:  When the page passes to "Print_Formats.php", I need to set the variable "$_SESSION['P_Format']".  "Print_Formats.php" has select buttons for 4 different formats.  If I use a select button on the form, how do I pass the it back to the global variable?
0
 

Author Comment

by:breeze351
ID: 38347131
Attached is the print screen from the above code.
Button-Problem.docx
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38347161
It's because PHP uses the whitespace, not ignores it when you do it like that.
Do it like this:
<?= $Button_Value; ?>

Open in new window

and it'll go away.
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38347206
To change the color of the number in the circle, you are not going to be able to change JUST the number. Since you are encoding the entity as
&#9312

Open in new window

this will produce a different colored number with circle:
<?php
    // Set The Value Of The Button
    $work = (9311 + $_SESSION['P_Format']);
    // Create The Button Value
    $Button_Value = "Print Format - <span style=\"color: #ff000;\">&#$work</span>";
?>

Open in new window

0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38347219
For #2, add a parameter to
MM_goToURL('parent', 'Print_Formats.php?p_format=$_GET["p_format"]');

Open in new window


Then set the session variable:
$_SESSION["P_Format"] = $_GET["p_format"];

Open in new window

0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38347242
As I mentioned in my earlier post try not to put the <?php on a new line after the opening quote

i.e.
'Print_Formats.php');return document.MM_returnValue" value="<?php echo $Button_Value;?>">

Open in new window

Instead of
'Print_Formats.php');return document.MM_returnValue" value="
        <?php
            echo $Button_Value;
            ?>
       
        ">

Open in new window

0
 

Author Comment

by:breeze351
ID: 38347296
It didn't work.   I changed the code to read:

   <!-- Print Format Button -->
    <?php
      // Set The Value Of The Button
    $work = (9311 + $_SESSION['P_Format']);
      
      // Create The Button Value
      $Button_Value = 'Print Format - '
      . ' '
      . '&#'
      . "$work";
      ?>
            <td align = "center" width="156">
        <input name="" type="button" id="Print_Formats" onClick="MM_goToURL('parent', 'Print_Formats.php');return document.MM_returnValue" value="
        <?= $Button_Value; ?>  
        ">
          </td>  
      <!-- End Print Format Button -->  

The button is still the same size as in the last print screen.
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38347304
As mentioned by more than one person here, DO NOT put the extra line breaks.
Post the code EXACTLY as I've shown and it will work.
If you are using Dreamweaver, don't let it reformat your code.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38347339
You did not change it as I described.

It should look like this.
<!-- Print Format Button -->
    <?php
      // Set The Value Of The Button
    $work = (9311 + $_SESSION['P_Format']);
      
      // Create The Button Value
      $Button_Value = 'Print Format - '
      . ' '
      . '&#'
      . "$work";
      ?>
            <td align = "center" width="156">
        <input name="" type="button" id="Print_Formats" onClick="MM_goToURL('parent', 'Print_Formats.php');return document.MM_returnValue" value="<?= $Button_Value; ?>">
          </td>  
      <!-- End Print Format Button -->  

Open in new window

0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38347429
julianH, it would be better formatted if he did it the way I suggested in #38347206
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38348936
@EddieShippman - the author does not seem to be following advice given. My first post would have solved the problem. My intention was to see if the code posted had the desired effect - posting different alternatives just serves to confuse the issue as there are now 4 different experts all giving different advice ultimately achieving the same end.

The question posed was why is there a space and the answer is that he was putting his php statements on a new line. Once we confirm that problem is solved we can start with the suggestions on how to better format the code. At least this is the way I deal with these situations - solve the problem first - lessons afterwards.
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38350071
Agreed
0
 
LVL 26

Accepted Solution

by:
Eddie Shipman earned 2000 total points
ID: 38350084
I think he may be using Dreamweaver because his code is being reformatted
0
 

Author Closing Comment

by:breeze351
ID: 38355603
Yes, it is Dreamweaver.  It's driving me nuts.  Thanks Eddie.  I put it on the same line and it works.  I would never have thought of this, the code looks correct and Dreamweaver genned it!
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 38355914
You should have split the points with julianH.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38356741
@breeze - I believe I suggested that in my first post ...

@EddieShipan - thanks for the vote of confidence.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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 …
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 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