Jump to content

JS Error


mark110384

Recommended Posts

Could anyone tell me why I've getting an error with the following coding? It works but I get an error in IE, "Undetermined string constant". the coding is

 


onClick="javascript: add_quote('<? echo "$reply_Msg"; ?>','<? echo "$ID_Reply"; ?>');"

 

Thanks

Link to comment
Share on other sites

1. Don't use short tags (i.e. <? ), use te full php tag ( <?php ).

2. Is this a javascript error or a PHP error? I'm assuming a JS error absed upon the forum you posted in. In that case you sheed to show the processed output. In otherwords, what is the result after being processed by PHP?

 

And, as a side note, why are you echoing a value in PHP and enclosign in quotes? PHP will first interpret the content in the quotes as a string and then have to revert any variables to their value. Just use echo $variable

Link to comment
Share on other sites

Thants for quotation tip, an example of the output that is being effected is

 


<table style="background-image: url(../images/quote_btn.PNG); background-repeat: no-repeat" border="0" width="62px"  cellpadding="3" cellspacing="0" onClick="javascript: add_quote('Another Test','262');" onMouseOver="this.style.cursor = 'pointer';">

 

The coding is for a button when you select it takes the $reply_Msg and using JS  pops it into a textarea and the $ID_Reply into a hidden text area. It only seems to happen with pages that have a quotation table included (Users can add quoted replies). The following is the quotation table with the buttons.

 

                        <br> <table border = "0" width="80%" align="center" style="border: 1px solid #555555" bgcolor = "#EEEEEE">
                          <tr> 
                            <td width="40px" style= "border-left: 10px solid #cccccc" rowspan = "2" valign="top"><img src="../images/quote_open.png" alt=""></td>
                            <td class="smalltxt"><b>QUOTE</b> (<? echo $quote_Author;?> 
                              @ <? echo $quote_Date;?>) </td>
                            <td rowspan="2" width="40px" valign="bottom"><img src="../images/quote_close.png" alt=""></td>
                          </tr>
                          <tr>
                            <td class="normaltxt"><? echo $quote_Msg; ?> </td>
                          </tr>
                        </table>
                        <br> 
                        <?
				 }


				  
				  
				  echo $reply_Msg; ?>
                      </td>
                    </tr>
                    <tr bgcolor="#CCCCCC"> 
                      <td colspan="2" style="border-top: solid 1px #AAA" align="right"> 
                        
					<? if(isset($name)){

						$onlcick_event = "javascript: add_quote('" . $reply_Msg . "','" . $ID_Reply . "');";
					}
					else{

						$onlcick_event ="window.location = '../forum_files/loginfrontend.php'";

					} 

				?>

					<table style="background-image: url(../images/quote_btn.PNG); background-repeat: no-repeat" border="0" width="62px"  cellpadding="3" cellspacing="0" onClick="<?php echo $onlcick_event; ?>" onMouseOver="this.style.cursor = 'pointer';">
                          <tr> 
                            <td width="10px"> </td>
                            <td valign="top" class="button_txt">QUOTE</td>
                          </tr>
                        </table>


					</td>
                      <td align="right" style="border-top: solid 1px #AAA"> <table style="background-image: url(../images/reply_btn.PNG); background-repeat: no-repeat" border="0" width="62px"  cellpadding="3" cellspacing="0" onClick="window.location = '<? echo "$link_status"; ?> ';" onMouseOver="this.style.cursor = 'pointer';">
                          <tr> 
                            <td width="13px"> </td>
                            <td valign="top" class="button_txt">REPLY</td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
                  <?

Link to comment
Share on other sites

Short tags may work in the environment you're in now but if you change web host (an example) and that web host doesn't have short tags enabled you've got a LOT of editing to do to make your scripts work.

 

Long tags (<?php) will always work where PHP is installed.

Link to comment
Share on other sites

Looking at the first code block in your last post, I see nothing wrong. where is the function being called? You're making this a lot more difficult for us to help you. With a Javascript error we need to see the rendered page code, NOT the PHP code. The problem could be somethign as simple as the code generated through PHP includes a quote mark that is fouling up the page.

 

Can you provide a link to the page that is giving you the problem?

Link to comment
Share on other sites

Unfortunately the website isn't is live yet the JS Function that the button calls is the following

 

function add_quote(message, id){

var msg = message;

var q_id = id;


document.getElementById("reply_txtbox").value = "<QUOTE>" + msg + "</QUOTE>";

document.getElementById("hidden_q_number").value = q_id;


}

 

It's quite puzzling as I don't see any errors in that either. FF isn't detecting an error but IE is?

Link to comment
Share on other sites

Well, again, you need to providfe more information. If IE is reporting an error, it would be indicating the line number of the error. What is the code that is areound that line number?

 

Assuming the IDs referenced in the getElementByID() calls are valid and are of the type that accept a value, the code above should be fine. But, why would you redefine the passed variables to the function? Just use this:

function add_quote(message, id)
{
document.getElementById('reply_txtbox').value = '<QUOTE>' + message + '</QUOTE>';
document.getElementById('hidden_q_number').value = id;
}

 

There's really nothing more I can provide to help based upon the info given. If you want additional help I would suggest copying the code from the entire rendered page into a flat html file and attaching to this thread. That way I, or someone else, can replicate the error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.