Solved

javascript working in IE but not in Firefox asp.net

Posted on 2010-08-27
7
689 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now