Solved

javascript working in IE but not in Firefox asp.net

Posted on 2010-08-27
7
690 Views
Last Modified: 2012-06-27
Hi,
I have a piece of code that doesn't work in firefox.
ISBNuseSame.Attributes.Add("onclick", "javascript:useSame(" + ISBNTextBox.ClientID + " , " + isbnValue + ");");

PPNuseSame.Attributes.Add("onclick", "javascript:useSame(" + PPNTextBox.ClientID + " , " + ppnValue + " );");

 on aspx page, i wrote a function:
 function useSame(textBoxId, textBoxValue) {
            alert(textBoxValue + textBoxId);textBoxId.value = textBoxValue;
          textBoxId.value = textBoxValue;            
        }
on ie, it works fine, on firefox, even the alert does not fire. Also, can you please tell me how do I five the textboxvalue to that textbox.
0
Comment
Question by:Dattu
  • 4
  • 2
7 Comments
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33544650
Hi

what type of controls are ISBNuseSame and PPNuseSame?
what are ISBNTextBox.ClientID and isbnValue, how are they being set?
does firefox give a javascript error and if so what is it?


0
 

Author Comment

by:Dattu
ID: 33544789
ISBN:
                   
                   
                   Use Same
                 
                     
               
               
                    PPN:
                   
                   Use Same
                   
               
<td>ISBN:</td>
                    <td><asp:TextBox ID="ISBNTextBox" runat="server" MaxLength="50"></asp:TextBox>
                   
                   <a href =# ID ="ISBNuseSame" runat = "server">Use Same</a> 
                  
                    </td> 
                </tr>
                <tr>
                    <td>PPN:</td>
                    <td><asp:TextBox ID="PPNTextBox" runat="server" MaxLength="20"></asp:TextBox>
                   <a href = # ID ="PPNuseSame" runat = "server">Use Same</a> </td>
                   
                </tr>

Open in new window

0
 

Author Comment

by:Dattu
ID: 33544798
the error given by firefox is:

Error: missing ; before statement
Source File: http://localhost:4257/Pages/CloneProduct.aspx?productid=68682
Line: 1, Column: 11
Source Code:
javascript:useSame'(ctl00_ctl00_PageContentPlaceHolder_MainContentPlaceHolder_ISBNTextBox , 1);'
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 38

Accepted Solution

by:
Tom Beck earned 125 total points
ID: 33544827
More than likely one or both of the values need to be in quotes for javascript:

ISBNuseSame.Attributes.Add("onclick", "javascript:useSame('" + ISBNTextBox.ClientID + "' , "' + isbnValue + "');");

Add single quotes inside double quotes where needed for string values.
0
 
LVL 17

Assisted Solution

by:jrm213jrm213
jrm213jrm213 earned 125 total points
ID: 33544896
from this:
javascript:useSame'(ctl00_ctl00_PageContentPlaceHolder_MainContentPlaceHolder_ISBNTextBox , 1);'

where are the ' coming from after useSame and all the way at the end ?

also

ctl00_ctl00_PageContentPlaceHolder_MainContentPlaceHolder_ISBNTextBox  I am guessing is the id of the control, you should need to put document.getElementById around it in your function in order to access it's value property, and tommyBoy is correct that you would need to have quotes around it in order to properly pass it.




ISBNuseSame.Attributes.Add("onclick", "javascript:useSame('" + ISBNTextBox.ClientID + "' , '" + isbnValue + "');");

PPNuseSame.Attributes.Add("onclick", "javascript:useSame('" + PPNTextBox.ClientID + "' , '" + ppnValue + "');");

on aspx page, i wrote a function:
function useSame(textBoxId, textBoxValue) {
            alert(textBoxValue + textBoxId);
          document.getElementById(textBoxId).value = textBoxValue;        
        }

Open in new window

0
 

Author Comment

by:Dattu
ID: 33544930
Sorry, what do you mean by adding single quotes inside double quotes. is this right?
   ISBNuseSame.Attributes.Add("onclick", "javascript:useSame('" + ISBNTextBox.ClientID + "' , '" + isbnValue + "');");
                    PPNuseSame.Attributes.Add("onclick", "javascript:useSame('" + PPNTextBox.ClientID + "' , '" + ppnValue + "');");
ISBNuseSame.Attributes.Add("onclick", "javascript:useSame('" + ISBNTextBox.ClientID + "' , '" + isbnValue + "');");
                    PPNuseSame.Attributes.Add("onclick", "javascript:useSame('" + PPNTextBox.ClientID + "' , '" + ppnValue + "');");

Open in new window

0
 

Author Comment

by:Dattu
ID: 33544956
got it. Thank You!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 the basics of jQuery including how to code hide show and toggles. 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…

896 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

11 Experts available now in Live!

Get 1:1 Help Now