473,563 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

External Js dosent work for multiple pages

67 New Member
hi,
Im new into Ajax and Javascript, I have a doubt...
I have a External javascript. and a couple of html files and I load These through ajax request and response.

The html pages contain a couple of image tag a check box and a input tag in order
on click i take the id of the check box ........ This works when i navigate through the page. but When i take the value of the corresponding checkbox ...... This dosent work when i navigate through the page.

Also When an check box is checked I need to show them checked even when i navigate through the pages.

It would be Great if i could move forward withyour help.


Thanks for your reply in advance....
Jun 8 '07 #1
13 2017
newlearner
67 New Member
Sorry i Dosent Work If I take The value of The Input Tag OF the Corresponding Check Box...

Suggestions PLS......
Jun 8 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Can you post some code.
Jun 9 '07 #3
newlearner
67 New Member
This Is My First Page.
<body>
<div id="productsMai n" class = "products">
<div id="products" style="font-weight:bold">Pr oducts Page1
<table border="0" cellpadding="0" >
<tr>
<td>
<div id="product_1" >
<table border="0" cellpadding="0" >
<tr>
<td></td>
<td class="box" id="image1"> Image 1 </td>
</tr>
<tr>
<td id="cost1" style="font-weight:bold" value="78" disabled=true>R s.78</td>
<td id="seltd1"><in put type = "checkbox" name = "shoppingProduc t" id="checkImage1 "></td>
</tr>
<tr>
<td>Qty</td>
<td id="qty1" style="font-weight:bold"><i nput type="text" id="sqty1" size="3" maxlength="3"></td></tr>
</tr>
</table>
</div>
</td>
<td>
<div id="product_2" >
<table border="0" cellpadding="0" >
<tr>
<td></td>
<td class="box" id="image2"> Image 2 </td></tr>
<tr>
<tr>
<td id="seltd2"><in put type = "checkbox" name = "shoppingProduc t" id="checkImage2 "></td>
<td id="cost2" style="font-weight:bold" value="400" disabled=true>R s.400</td>
</tr>
<tr>
<td>Qty</td>
<td id="qty2" style="font-weight:bold"><i nput type="text" id="sqty2" size="3" maxlength="3"></td></tr>
</tr>
</table>
</div>
</td>

--- Part of the first page. it is the same for products up to 10

The end of the page where the function is called


<div class="clearCar t" id="AddtoCart" onclick="AddtoC art();">Add to Cart</div>
</div>
</div>
</div>
<table align="right" border="0" style="padding-right:200px">
<tr >
<td><input type="button" id="previous" disabled="true" value ="<< prev" onClick="nextPa ge('prevPg');"> </td>
<td>    </td>
<td><input type="button" value ="next >>" id="next" onClick="nextPa ge('nextPg');"> </td>
</tr>
</table>
<div id="cartid" style="position :absolute;left: 700px;backgroun d:#FFFF66;borde r:1px dashed gray;top:20px;d isplay:none"></div>

*************** *************** *************** *************** *************** **************

This is My Second Page.

<div style="font-weight:bold">Pr oducts Page2
<table border="0" cellpadding="0" >
<tr>
<td>
<div id="product_11" >
<table border="0" cellpadding="0" >
<tr>
<td></td>
<td class="box" id="image11"> Image 11 </td>
</tr>
<tr>
<td id="cost11" style="font-weight:bold">Rs .300</td>
<td id="seltd11"><i nput type = "checkbox" name = "shoppingProduc t" id="checkImage1 1"></td>
</tr>
<tr>
<td>Qty</td>
<td id="qty11" style="font-weight:bold"><i nput type="text" id="sqty11" size="3" maxlength="3"></td></tr>
</tr>
</table>
</div>
</td>
<td>
<div id="product_12" >
<table border="0" cellpadding="0" >
<tr>
<td></td>
<td class="box" id="image12"> Image 12 </td>
</tr>
<tr>
<td id="cost12" style="font-weight:bold">Rs .70</td>
<td id="seltd12"><i nput type = "checkbox" name = "shoppingProduc t" id="checkImage1 2"></td>
</tr>
<tr>
<td>Qty</td>
<td id="qty12" style="font-weight:bold"><i nput type="text" id="sqty12" size="3" maxlength="3"></td></tr>
</tr>
</table>
</div>
</td>
<td>
<div id="product_13" >
<table border="0" cellpadding="0" >
<tr>
<td></td>
<td class="box" id="image13"> Image 13 </td>
</tr>
<tr>
<td id="cost13" style="font-weight:bold">Rs .55</td>
<td id="seltd13"><i nput type = "checkbox" name = "shoppingProduc t" id="checkImage1 3"></td>
</tr>
<tr>
<td>Qty</td>
<td id="qty13" style="font-weight:bold"><i nput type="text" id="sqty13" size="3" maxlength="3"></td></tr>
</tr>
</table>
</div>
</td>
<td>

This page end with products from 11 to 20 no functions os js is found or called in this page

*************** *************** *************** *************** *************** ***********



The Js File with the functions that are called

var productAry = new Array;
var theObj ="";
document.onclic k = function(e){
var theObj = e.target || event.srcElemen t;
var theId ="";
if(theObj.type == "checkbox") {
var theId = theObj.id
if(theObj.check ed){
if(!productAry. inArray(theId))
for(var i=0;i<imageAry. length;i++){
if(theId == imageAry[i]){
productAry.push (imageAry[i]);
}
}






function AddtoCart(){
var topDiv = "<table border='1'><tr> <td colspan='4' align='center' style='border:1 px solid red;font-weight:bold'> Selected Items</td></tr>"
topDiv += "<tr style='font-weight:bold'><t d></td><td>Cost/Item</td></td>No.Of Items Ordered</td><td>Total</td></tr>";
for(var i=0;i<imageAry. length;i++){
var addId = imageAry[i];
//var selQty = addId.findandre place("checkIma ge","sqty");
//var selCost = addId.findandre place("checkIma ge","cost");

//var selQtyValue = document.getEle mentById(selQty ).value
//var selCostValue = document.getEle mentById(selCos t).innerHTML;
//selCostValue = selCostValue.su bstring(3);
//if(document.get ElementById(sel Qty).value !=""){
topDiv +="<tr>";
//topDiv +="<td><input type ='checkbox' id= checked"+i+" CHECKED></td>"
//topDiv +="<td>Rs."+sel CostValue+"</td>"
//topDiv +="<td align='center'> <input type = 'text' id="+"sel"+selQ ty+" value="+selQtyV alue+" size='3' ></td>"
//topDiv +="<td>"+selCos tValue*selQtyVa lue+"</td></tr>"
topDiv +="<td>"+addId+ "</td></tr>"
//}
//else
// alert("Please Enter the Quantity");

}
topDiv +="<tr><td colspan='5'><in put type='Button' value='Buy The List' onClick='' </td></tr>"
topDiv +="</table>";
//if(document.get ElementById(add Id).checked && document.getEle mentById(selQty ).value != ""){
document.getEle mentById("carti d").innerHTM L = topDiv;
document.getEle mentById("carti d").style.displ ay="block";
//}



...Hop This Helps.
Looking forward ..

Thanks in advance
Jun 11 '07 #4
dmjpro
2,476 Top Contributor
I m little bit doubt about when a HTML page with some JS code is loaded using AJAX.
Actually the JS code is invalid untill it placed in a browser.
Actually AJAX is made for loading XML and parse it.
But there loading a HTML page and parse it .. this is nothing but a stupid job.
I think u got my point.

Kind regards,
Dmjpro.
Jun 11 '07 #5
newlearner
67 New Member
we can parse a xml doc and show it in the browser . Also it works well with html too There is no need to parse a html doc. It can be displayed straight away from the respose.

All That is done there is a time save in Ajax rather than the other way.

All i need is the function Addtocart to be global for every page that is loaded.
I dont want to write or refer a js function on every page. I just want to write a global js function that works on every page which is loaded through.


Since my Addtocart function is loaded and called inthe main Page.(the html part is loaded only for the check boxes and images) I would like to use the function globally.

is there any way to acheive it...
looking Forward
Jun 11 '07 #6
dmjpro
2,476 Top Contributor
we can parse a xml doc and show it in the browser . Also it works well with html too There is no need to parse a html doc. It can be displayed straight away from the respose.

All That is done there is a time save in Ajax rather than the other way.

All i need is the function Addtocart to be global for every page that is loaded.
I dont want to write or refer a js function on every page. I just want to write a global js function that works on every page which is loaded through.


Since my Addtocart function is loaded and called inthe main Page.(the html part is loaded only for the check boxes and images) I would like to use the function globally.

is there any way to acheive it...
looking Forward

Ok frnd ... see.
The AJAX is for loading the page but not rendering the page into the browser.
Right?
If u want to load and render the page then use simple page navigation.
Right?
AJAX means u r accessing a some updated data which u need to update the main page with the help of those data.

Kind regards,
Dmjpro.
Jun 11 '07 #7
newlearner
67 New Member
Thats right Pal...

All im concerned about is can a global js function be used to multiple pages without reference.

Wat i have done is ...
There are a couple of pages which are of the same type. i have one js function loaded externally.

This function works good just for one page no matter on which page the function is first called(Page 1 or 2 or 3..).But never works when the same function is called in another page without refreshing.
Can this js function made in such a way that it works good for all pages without refreshing.. So that there is no need to refer the function in every page.


May be it looks bit wierd ... But im intrested to know wether this could be attained.

eagerly Looking Forward

Hope this could be attained
Jun 11 '07 #8
dmjpro
2,476 Top Contributor
Thats right Pal...

All im concerned about is can a global js function be used to multiple pages without reference.

Wat i have done is ...
There are a couple of pages which are of the same type. i have one js function loaded externally.

This function works good just for one page no matter on which page the function is first called(Page 1 or 2 or 3..).But never works when the same function is called in another page without refreshing.
Can this js function made in such a way that it works good for all pages without refreshing.. So that there is no need to refer the function in every page.


May be it looks bit wierd ... But im intrested to know wether this could be attained.

eagerly Looking Forward

Hope this could be attained

Yes u can do this using one global JS and handle multiple pages but there is no need of AJAX.
Rewrite the code without JS then try to do what u want.
Right?
Best of luck.

Kind regards,
Dmjpro.
Jun 11 '07 #9
newlearner
67 New Member
Dmjpro.. Thanks for your Comments
My Concern is...

Suppose i access multiple pages through ajax.
I load the initial page with the external js file . Through ajax i replace a part of the page.

Now If i access then js function holds good to the first page from where the function is called.i.e if the click on the link to call the function is from the third page then it works good for third page only and it dosent work for the second click to call the function in page 1 or 2. But i need the function to be working on all pages for more clicks.

i need an idea to work on this ...

I need Help

Thanks and Looking Forward.
Jun 11 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

47
3819
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
8
1980
by: Flip | last post by:
I have a website that's using Master pages (very cool). But when I put JS on there (to close the browser for example) coming from an external file, when I navigate away from the first page, the JS no longer works. Can someone explain why this is happening? How can I fix this so that the JS is generic enough to work on every aspx to be...
1
8103
by: pseudomagazine | last post by:
Little problem: Using the document.write() function and an enormous string, I have managed to create self-generated pages with functions calling code located in external scripts. The code that generates these pages is linked to these pages from within the document.write() string. So far so good. I lifted on the internet a supercode...
1
2431
by: iahamed via WebmasterKB.com | last post by:
HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. It never works. Vista dosent load my ASp pages can some one help me to get this working. I have set permitions to the wwwroot and full...
0
7658
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...
0
7579
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...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7940
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...
0
6228
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...
0
5198
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
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...
0
3609
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.