I have wriiten the following code: <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Calling Function</title> <script> function showCustomer(str) { var xmlhttp; if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://ps8471.persistent.co.in:8080/AjaxCode/DBUpdator?id="+str,true); xmlhttp.send(); } function showCustomer1(str,str1) { var xmlhttp; if (str=="") { //alert(document.getElementById("txtHint").innerHTML); document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { // alert(xmlhttp.responseText); document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://ps8471.persistent.co.in:8080/AjaxCode/DBUpdatorShow?tag="+str+"&id="+str1,true); xmlhttp.send(); // clears text value document.getElementById('tag').value = ""; } function getParams() { var idx = document.URL.indexOf('='); var tempParams = new Object(); if (idx != -1) { var pairs = document.URL.substring(idx+1, document.URL.length); } return pairs; } var p = getParams(); </script> </head> <body onload="showCustomer(p)" > <!--onload="showCustomer('I00012353');"--> <div id="txtHint">Indent info will be listed here...</div> Kinjal's Part Intent ID: I00012353 <br/> Tag: Tags from database will come here <br/> <input type="text" name="tag" id="tag" > <button type="submit" onclick="showCustomer1(document.getElementById('tag').value,'I00012353')">Add Tag</button> <br></body> </html> --> I want body onload to be displayed and onclick value in text box to be taken as input.but here at the same time both things are happening.please help me out urgently
Change your server code so that the <body> statement is written to show the customer number you get from the database. Something like <body onload="showCustomer(<?php echo $customerNumber; ?> )" > <!--onload="showCustomer('I00012353');"-->
through show customer funstion I have given call to java code, where that database is linked..some other solution?
You're writing a bunch of spaghetti that, I think, would be a lot simpler if you first thought about what you have to do, not how to do it. 'How' comes after you simplify 'what'. (You write computer programs in English before you start to write any code.) There are a few problems. If there's no argument to the URL, getParams returns an undefined variable. (You only define 'pairs' if there's an argument, but you return it even if there isn't.) It also defines tempParams but never uses it. I00012353 seems to be a constant, so there's no need to send it all over the place. And define a single function to create your xmlhttp, then just call it from where you need it. There's no reason to duplicate code, it just slows the load time.