473,770 Members | 7,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem retreiving value in javascript

I have recently created a ASP site utilizing Master Pages and all works fine
until I want to proces my javascripts. Just to let you know, most of
cliewnt side scripting is new to me.

But anyway,

I can retrieve and updat ethe value a textbox on the page by using the

document.getEle mentById('Goals _Main_tbProduct 0').value

by not by using

document.getEle mentById('<%=tb Product0.Client ID%>').value

I would prefer to use the latter because I have read that is a much leaner
way to process just in case you page ever changes or if you ever add any
additional complexity to it. But evertime I try to retrieve the value it
returns a null value or if I try to set hte value I get Microsoft JScript
runtime error: 'document.getEl ementById(...)' is null or not an object.

Can anyone give me any advice, this is getting rather annoying.
Thanks

Aug 17 '06 #1
4 1584
Hi,

James Pemberton wrote:
I have recently created a ASP site utilizing Master Pages and all works fine
until I want to proces my javascripts. Just to let you know, most of
cliewnt side scripting is new to me.

But anyway,

I can retrieve and updat ethe value a textbox on the page by using the

document.getEle mentById('Goals _Main_tbProduct 0').value

by not by using

document.getEle mentById('<%=tb Product0.Client ID%>').value

I would prefer to use the latter because I have read that is a much leaner
way to process just in case you page ever changes or if you ever add any
additional complexity to it. But evertime I try to retrieve the value it
returns a null value or if I try to set hte value I get Microsoft JScript
runtime error: 'document.getEl ementById(...)' is null or not an object.

Can anyone give me any advice, this is getting rather annoying.
Thanks
What is the HTML/JavaScript code produced by the server? Open your page
in IE and then select View Source. This way, you can see what code the
server created, and that should help you to find the error.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 17 '06 #2
Thank Laurent that pointed me in somewhat of a starting direction. I
originally had this script stored in an external JavaScript file in VS 2005
and the ClientID would not work, but I change my ASP page and imbedded the
script. When I then viewed it on the page it appeared to translate it
correctly.

So now my question is, how to I get my external script to work the same way?
Or can I?

I was referencing my other script like so:
<script src="Scripts/Goals_script.js " language="javas cript"
type="text/javascript"></script>

Thanks

"Laurent Bugnion" <ga*********@bl uewin.chwrote in message
news:e6******** ******@TK2MSFTN GP05.phx.gbl...
Hi,

James Pemberton wrote:
>I have recently created a ASP site utilizing Master Pages and all works
fine until I want to proces my javascripts. Just to let you know, most
of cliewnt side scripting is new to me.

But anyway,

I can retrieve and updat ethe value a textbox on the page by using the

document.getEl ementById('Goal s_Main_tbProduc t0').value

by not by using

document.getEl ementById('<%=t bProduct0.Clien tID%>').value

I would prefer to use the latter because I have read that is a much
leaner way to process just in case you page ever changes or if you ever
add any additional complexity to it. But evertime I try to retrieve the
value it returns a null value or if I try to set hte value I get
Microsoft JScript runtime error: 'document.getEl ementById(...)' is null
or not an object.

Can anyone give me any advice, this is getting rather annoying.
Thanks

What is the HTML/JavaScript code produced by the server? Open your page in
IE and then select View Source. This way, you can see what code the server
created, and that should help you to find the error.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Aug 17 '06 #3
Hi,

James Pemberton wrote:
Thank Laurent that pointed me in somewhat of a starting direction. I
originally had this script stored in an external JavaScript file in VS 2005
and the ClientID would not work, but I change my ASP page and imbedded the
script. When I then viewed it on the page it appeared to translate it
correctly.

So now my question is, how to I get my external script to work the same way?
Or can I?

I was referencing my other script like so:
<script src="Scripts/Goals_script.js " language="javas cript"
type="text/javascript"></script>

Thanks
OK, now I understand your problem better. It's really an understanding
problem: You need to understand that only the ASPX page is processed by
the server, and the <%= ... %syntax will only work when written in the
ASPX page itself. All linked files (CSS, JavaScript) will not be processed.

What you can do however is use a variable to define the textbox's client
ID. Since every bit JavaScript on your page and also the scripts defined
in external files run in the same engine, you can define a variable in
the ASPX page and use it inside your external script. For example:

In the ASPX page:

string strScript = "<script type=\"text/javascript\">"
+ Environment.New Line
+ "var strTextboxId = '" + tbProduct0.Clie ntID + "';"
+ Environment.New Line
+ "</script>";

this.ClientScri pt.RegisterClie ntScriptBlock( typeof( YourPage ),
"TextboxIdScrip t",
strScript );
Then in the JavaScript file:

if ( strTextboxId )
{
var nTextbox = document.getEle mentById( strTextboxId );
if ( nTextbox
&& nTextbox.value )
{
// Use nTextbox.value
}
}
Sorry, didn't have time to test.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 17 '06 #4
Thanks again Laurent, you pointed me in a direction to actually utilize both
internal variables and external scripts.
Just for someone else's information that might run into this same problem.
I know this might not be the most efficient way, but it worked

I had a group of textboxes I wanted to process with various functions.
I create an array on my asp page defining each element as my client id for
the box:
TextBoxArray[1] = '<%=Textbox1.Cl ientID%>'
TextBoxArray[2] = '<%=Textbox2.Cl ientID%>'
and so on

Then in my external Javascript file I just had to reference the array to
obtain all of the client id names for my text boxes.

It's a good thing to learn soemthing new everyay!

"Laurent Bugnion" <ga*********@bl uewin.chwrote in message
news:u1******** ******@TK2MSFTN GP06.phx.gbl...
Hi,

James Pemberton wrote:
>Thank Laurent that pointed me in somewhat of a starting direction. I
originally had this script stored in an external JavaScript file in VS
2005 and the ClientID would not work, but I change my ASP page and
imbedded the script. When I then viewed it on the page it appeared to
translate it correctly.

So now my question is, how to I get my external script to work the same
way? Or can I?

I was referencing my other script like so:
<script src="Scripts/Goals_script.js " language="javas cript"
type="text/javascript"></script>

Thanks

OK, now I understand your problem better. It's really an understanding
problem: You need to understand that only the ASPX page is processed by
the server, and the <%= ... %syntax will only work when written in the
ASPX page itself. All linked files (CSS, JavaScript) will not be
processed.

What you can do however is use a variable to define the textbox's client
ID. Since every bit JavaScript on your page and also the scripts defined
in external files run in the same engine, you can define a variable in the
ASPX page and use it inside your external script. For example:

In the ASPX page:

string strScript = "<script type=\"text/javascript\">"
+ Environment.New Line
+ "var strTextboxId = '" + tbProduct0.Clie ntID + "';"
+ Environment.New Line
+ "</script>";

this.ClientScri pt.RegisterClie ntScriptBlock( typeof( YourPage ),
"TextboxIdScrip t",
strScript );
Then in the JavaScript file:

if ( strTextboxId )
{
var nTextbox = document.getEle mentById( strTextboxId );
if ( nTextbox
&& nTextbox.value )
{
// Use nTextbox.value
}
}
Sorry, didn't have time to test.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Aug 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3035
by: The Roys | last post by:
Hi I have a textbox which displays a formatted numeric. eg: 100,000 When I retreive this value for calculations, it is valued at 100 eg: calc = val(txtbox) * 2 calc will equal 200, not 200,000. Why is this, how do I fix it ??
2
1256
by: Reddy | last post by:
Hi, Once after inserting a record into a table is there a more efficient way of retreiving the id(autonumber field) value in the following example. Using a SQL server database. con.Open() strSql="insert into table1(column2) values('test1')" cmd = New OdbcCommand(strSql, con)
0
1128
by: yogeeswar | last post by:
HI ALL I AM USING DB2 8.1 AND I HAVE TWO TABLES PARENT TABLE 1)CODE IS PRIMARY KEY CODE CODE_DESC CATEGORY ----------- ---------------------------------------- ---------- ------------ 1 SelectByPlan A 2 SPT A 3 SP A
0
1960
by: kmithu | last post by:
Hey friends, I am making a calender control using javascript but I am not able to retrieve its value on my .aspx.cs coding page in asp.net2.0. My text box code is : <input type="text" class="fancy" size="10" maxlength="10" readonly="readonly" name="date1" value="" id="txtDob"/> <input type="button" class="fancyButton" onclick="setDate('date1')" value="DOB" /> When i give the input type="text" a runat="server" tag, it gives an error...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.